diff options
| author | Kenneth Shaw <[email protected]> | 2017-03-03 19:12:17 +0700 |
|---|---|---|
| committer | Kenneth Shaw <[email protected]> | 2017-03-04 09:13:12 +0700 |
| commit | d4c2b35b2ef5b67c3ec6f904cea0dff806d51e2c (patch) | |
| tree | 7c7b0944f564159efb512ceca0c562c475249960 /README.md | |
| parent | 8488cf10ceffaa0c78f84ce82b38374c3e546940 (diff) | |
Adding separate tag option
As outlined in #49, there is a need to mimic the behavior of other
applications by interweaving positional and non-positional parameters.
This change adds the 'separate' option that will force a arg of type
[]string to only read the next supplied value.
For example, when dealing with the following arg type:
var MyArgs struct {
Pos []string `arg:"positional"`
Separate []string `arg:"-s,separate"`
}
This commit will parse the following command line:
./app pos1 pos2 -s=separate1 -s=separate2 pos3 -s=separate3 pos4
Such that MyArgs.Pos will be [pos1 pos2 pos3 pos4] and MyArgs.Separate
will be [separate1 separate2 separate3].
Unit tests for the above have also been written and are included in this
commit, as well as the addition of a section to README.md and an example
func in example_test.go.
Fixes #49
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -108,7 +108,7 @@ arg.MustParse(&args) ```shell $ ./example -h -usage: [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--help] INPUT [OUTPUT [OUTPUT ...]] +usage: [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--help] INPUT [OUTPUT [OUTPUT ...]] positional arguments: input @@ -148,6 +148,22 @@ fmt.Printf("Fetching the following IDs from %s: %q", args.Database, args.IDs) Fetching the following IDs from foo: [1 2 3] ``` +### Arguments that can be specified multiple times, mixed with positionals +```go +var args struct { + Commands []string `arg:"-c,separate"` + Files []string `arg:"-f,separate"` + Databases []string `arg:"positional"` +} +``` + +```shell +./example -c cmd1 db1 -f file1 db2 -c cmd2 -f file2 -f file3 db3 -c cmd3 +Commands: [cmd1 cmd2 cmd3] +Files [file1 file2 file3] +Databases [db1 db2 db3] +``` + ### Custom validation ```go var args struct { |
