All Projects → sg3des → argum

sg3des / argum

Licence: Unlicense license
Parse incoming arguments in to structure

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to argum

Kong
Kong is a command-line parser for Go
Stars: ✭ 481 (+2572.22%)
Mutual labels:  struct, flags
pflag
Generic PHP command line flags parse library
Stars: ✭ 14 (-22.22%)
Mutual labels:  flags
ld-redux
A library to integrate launch darkly with react redux
Stars: ✭ 33 (+83.33%)
Mutual labels:  flags
govalidators
struct 验证器,内置大部分常用验证,可自定义
Stars: ✭ 56 (+211.11%)
Mutual labels:  struct
vue-flagpack
Flagpack contains 260+ easily implementable flag icons to use in your design or code project.
Stars: ✭ 42 (+133.33%)
Mutual labels:  flags
hacker
Hack on your project easily. A liftoff proof-of-concept.
Stars: ✭ 21 (+16.67%)
Mutual labels:  flags
graphcountries
An easy to use GraphQL API to query country-related data for free and without restrictions
Stars: ✭ 61 (+238.89%)
Mutual labels:  flags
valify
Validates data in JavaScript in a very simple way
Stars: ✭ 13 (-27.78%)
Mutual labels:  struct
react-flagkit
🇺🇦 React wrapper for FlagKit Flag Icons
Stars: ✭ 21 (+16.67%)
Mutual labels:  flags
cstruct-go
a fast c-style struct packer & unpacker for golang
Stars: ✭ 28 (+55.56%)
Mutual labels:  struct
react-circle-flags
🚀 A React component with a collection of 300+ minimal circular SVG country flags. Wrapper of HatScripts/circle-flags
Stars: ✭ 29 (+61.11%)
Mutual labels:  flags
c-compiler-security
Security-related flags and options for C compilers
Stars: ✭ 125 (+594.44%)
Mutual labels:  flags
GraphQL.RepoDB
A set of extensions for working with HotChocolate GraphQL and Database access with micro-orms such as RepoDb (or Dapper). This extension pack provides access to key elements such as Selections/Projections, Sort arguments, & Paging arguments in a significantly simplified facade so this logic can be leveraged in the Serivces/Repositories that enca…
Stars: ✭ 25 (+38.89%)
Mutual labels:  arguments
genstruct
Golang struct generator similar to mysql terminal
Stars: ✭ 18 (+0%)
Mutual labels:  struct
args-parser
args-parser is a small C++ header-only library for parsing command line arguments.
Stars: ✭ 53 (+194.44%)
Mutual labels:  arguments
freecli
Command line parsing library using Free Applicative
Stars: ✭ 29 (+61.11%)
Mutual labels:  arguments
python-cstruct
C-style structs for Python
Stars: ✭ 38 (+111.11%)
Mutual labels:  struct
flagg
Barebones subcommand handling
Stars: ✭ 55 (+205.56%)
Mutual labels:  flags
straf
Convert Golang Struct To GraphQL Object On The Fly
Stars: ✭ 33 (+83.33%)
Mutual labels:  struct
go-httpheader
A Go library for encoding structs into Header fields.
Stars: ✭ 38 (+111.11%)
Mutual labels:  struct

Build Status

Argum

Argum is package for parse arguments into struct, inspired by alexflint/go-arg.

WARNING! work in progress, backward compatible is not guaranteed!

go get github.com/sg3des/argum

Description

Setting up available arguments using tags:

  • argum:"-s" - set short signature
  • argum:"--str" - set long signature
  • argum:"-s,--str" - set short and long signature
  • argum:"req" or argum:"required" - required argument
  • argum:"pos" or argum:"positional" - positional argument
  • argum:"oneof" - this keyword work only on internal struct, user can select only one of nested fields, itself structure ignored from command line
  • argum:"emb" or argum:"embedded" - its keyword work only on for internal struct, and indicates that the struct name should be ignored
  • help:"some help" - help description for this option
  • default:"value" - default value
  • if struct field not have tag argum, then parse it automate

Argum, use 3 key tags for parse structure - argum, help, default - it's more convenient.

Usage

var args struct {
	A string                      //parsed to -a
	Arg string                    //parsed to --arg
	SomeArg string `argum:"-s"`   //only -s
	OneMoreArg string `argum:"-o,--onemore"`  //both keys: -o, --onemore
}
argum.MustParse(&args)

Set software version

argum.Version = "some version"
argum.MustParse(&args)

Default values

var args struct {
	String string    `default:"some string"`
	Slice  []string  `default:"one,two,three"`
	IntSlice []int `argum:"--int" default:"0,2,3"`
}

Default value for slice automatic split by comma character

Joined boolean arguments

var args struct {
	A bool
	B bool
	C bool `argum:"-c"`
	D bool
	E bool 
}
argum.MustParse(&args)

This options can be specified as ./example -abcde, and each of listed will be set to true

Internal structs and oneof keyword

var args struct {
	Command Commands `argum:"req,oneof" help:"select main command"`

	Listen *Echo `help:"optional internal struct"`

	Value string `argum:"pos" help:"Some string value"`
	Debug bool   `argum:"-d,--debug" help:"Enable debug mode"`
}

type Commands struct {
	Ping *Ping  `help:"some ping"`
	Echo *Echo  `help:"open local port"`
	Str  string `argum:"pos" help:"simple string value instead struct"`
}

type Ping struct {
	IP    string `argum:"req,pos" help:"ip address"`
	Count int    `argum:"-c" help:"count of packets"`
}

type Echo struct {
	Port int `argum:"req,pos" help:"port number"`
}

Keyword oneof is means user should chose only one of nested fields. These example structures will provide next command lines:

./example ping 127.0.0.1
./example -d ping 127.0.0.1
./example ping 127.0.0.1 -c4
./example ping 127.0.0.1 -c4 listen 8000

./example echo 8080
./example echo 8080 -d
./example echo 8080 listen 8000

Embedding structs

var args struct {
	Ping `argum:"emb"`
}

type Ping struct {
	IP string `argum:"pos,req"`
	Count int    `argum:"-c" help:"count of packets"`
}

Keyword emb or embedded indicates that the structure name should be ignored. These example will provide next command lines:

./example 127.0.0.1
./example 127.0.0.1 -c 4

Help and Usage output

var args struct {
	A bool `help:"a option, enable something"`
	B bool `help:"if true, then something will happen"`
	C bool `help:"c enable something"`

	S      string `argum:"req,str0|str1|str2" help:"required value for something"`
	String string `help:"set string value"`

	Arg        string `argum:"-a" help:"optional you may set Arg variable"`
	OneMoreArg string `argum:"-o,--onemore" default:"some-value" help:"one more arg"`

	Pos string `argum:"pos,debug|normal|fast" default:"normal" help:"mode"`
}
argum.Version = "example version 0.1.2"
argum.MustParse(&args)
usage: example [-abc] -s=[str0|str1|str2] [--string=<s>] [-a=<s>] [-o=<s>] [debug|normal|fast]

positional:
  pos                     mode [default: normal] [debug|normal|fast]

options:
  -a                      a option, enable something
  -b                      if true, then something will happen
  -c                      c enable something
  -s=[str0|str1|str2]     required value for something [str0|str1|str2]
      --string=<s>        set string value
  -a=<s>                  optional you may set Arg variable
  -o, --onemore=<s>       one more arg [default: some-value]
  -h, --help              display this help and exit
      --version           display version and exit

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].