From d7961941f0ceee4e55062041991de7bbd43b2b57 Mon Sep 17 00:00:00 2001 From: Rick Date: Mon, 2 Oct 2017 14:18:41 +0100 Subject: Altered help tag parsing to reduce the constraints on help text content; old behaviour is retained for backward compatibility --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 3f9223c..18e572d 100644 --- a/README.md +++ b/README.md @@ -99,9 +99,9 @@ Workers: 4 var args struct { Input string `arg:"positional"` Output []string `arg:"positional"` - Verbose bool `arg:"-v,help:verbosity level"` - Dataset string `arg:"help:dataset to use"` - Optimize int `arg:"-O,help:optimization level"` + Verbose bool `arg:"-v" help:"verbosity level"` + Dataset string `help:"dataset to use"` + Optimize int `arg:"-O" help:"optimization level"` } arg.MustParse(&args) ``` @@ -306,7 +306,7 @@ Options: --help, -h display this help and exit ``` -### Documentation +### API Documentation https://godoc.org/github.com/alexflint/go-arg @@ -319,3 +319,7 @@ The shortcomings of the `flag` library that ships in the standard library are we Many third-party argument parsing libraries are geared for writing sophisticated command line interfaces. The excellent `codegangsta/cli` is perfect for working with multiple sub-commands and nested flags, but is probably overkill for a simple script with a handful of flags. The main idea behind `go-arg` is that Go already has an excellent way to describe data structures using Go structs, so there is no need to develop more levels of abstraction on top of this. Instead of one API to specify which arguments your program accepts, and then another API to get the values of those arguments, why not replace both with a single struct? + +### Backward Compatibility Notes + +The tags have changed recently. Earlier versions required the help text to be part of the `arg` tag. This is still supported but is now deprecated. Instead, you should use a separate `help` tag, described above, which removes most of the limits on the text you can write. -- cgit v1.2.3 From ba9514f0be00c17e53b4e0e255bcb9482354935f Mon Sep 17 00:00:00 2001 From: Rick Date: Mon, 2 Oct 2017 14:36:23 +0100 Subject: Further clarification --- README.md | 5 ++++- usage_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 18e572d..18dc556 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,9 @@ Options: --help, -h print this help message ``` +As the example above shows, the `help` tag can be used in conjunction with `arg`, or instead. When used +together, they can appear in either order. + ### Default values ```go @@ -322,4 +325,4 @@ The main idea behind `go-arg` is that Go already has an excellent way to describ ### Backward Compatibility Notes -The tags have changed recently. Earlier versions required the help text to be part of the `arg` tag. This is still supported but is now deprecated. Instead, you should use a separate `help` tag, described above, which removes most of the limits on the text you can write. +The tags have changed recently. Earlier versions required the help text to be part of the `arg` tag. This is still supported but is now deprecated. Instead, you should use a separate `help` tag, described above, which removes most of the limits on the text you can write. In particular, you will need to use the new `help` tag if your help text includes any commas. diff --git a/usage_test.go b/usage_test.go index bdf4ea2..940bf40 100644 --- a/usage_test.go +++ b/usage_test.go @@ -65,13 +65,13 @@ func TestUsageLongPositionalWithHelp_legacyForm(t *testing.T) { Positional arguments: VERYLONGPOSITIONALWITHHELP - this positional argument is very long + this positional argument is very long but cannot include commas Options: --help, -h display this help and exit ` var args struct { - VeryLongPositionalWithHelp string `arg:"positional,help:this positional argument is very long"` + VeryLongPositionalWithHelp string `arg:"positional,help:this positional argument is very long but cannot include commas"` } p, err := NewParser(Config{}, &args) @@ -88,13 +88,13 @@ func TestUsageLongPositionalWithHelp_newForm(t *testing.T) { Positional arguments: VERYLONGPOSITIONALWITHHELP - this positional argument is very long + this positional argument is very long, and includes: commas, colons etc Options: --help, -h display this help and exit ` var args struct { - VeryLongPositionalWithHelp string `arg:"positional" help:"this positional argument is very long"` + VeryLongPositionalWithHelp string `arg:"positional" help:"this positional argument is very long, and includes: commas, colons etc"` } p, err := NewParser(Config{}, &args) -- cgit v1.2.3