diff options
| author | Alex Flint <[email protected]> | 2022-10-29 15:19:23 -0400 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2022-10-29 15:19:23 -0400 |
| commit | 3d95a706a6a1cc80d62f403778c5d160698003b0 (patch) | |
| tree | b451fc515320dc6721dacc601b799266a8f78c3b /README.md | |
| parent | d949871b676ed52669c17c2070dfb770b6ce28da (diff) | |
| parent | dbc2ba5d0c9a6a439d1f825f8c299fb276bbc911 (diff) | |
Merge remote-tracking branch 'origin/master' into default-value-issue
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 54 |
1 files changed, 52 insertions, 2 deletions
@@ -134,10 +134,10 @@ 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 + INPUT OUTPUT Options: @@ -180,6 +180,24 @@ var args struct { arg.MustParse(&args) ``` +#### Ignoring environment variables and/or default values + +The values in an existing structure can be kept in-tact by ignoring environment +variables and/or default values. + +```go +var args struct { + Test string `arg:"-t,env:TEST" default:"something"` +} + +p, err := arg.NewParser(arg.Config{ + IgnoreEnv: true, + IgnoreDefault: true, +}, &args) + +err = p.Parse(os.Args) +``` + ### Arguments with multiple values ```go var args struct { @@ -444,6 +462,9 @@ Options: ### Description strings +A descriptive message can be added at the top of the help text by implementing +a `Description` function that returns a string. + ```go type args struct { Foo string @@ -469,6 +490,35 @@ Options: --help, -h display this help and exit ``` +Similarly an epilogue can be added at the end of the help text by implementing +the `Epilogue` function. + +```go +type args struct { + Foo string +} + +func (args) Epilogue() string { + return "For more information visit github.com/alexflint/go-arg" +} + +func main() { + var args args + arg.MustParse(&args) +} +``` + +```shell +$ ./example -h +Usage: example [--foo FOO] + +Options: + --foo FOO + --help, -h display this help and exit + +For more information visit github.com/alexflint/go-arg +``` + ### Subcommands *Introduced in version 1.1.0* |
