From 0f0b4b5c3f9dfab413c3127830b869bc7d4b0e27 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Sat, 18 Sep 2021 08:50:33 -0700 Subject: [PATCH] Update README.md --- README.md | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 855c02e..dab2996 100644 --- a/README.md +++ b/README.md @@ -158,19 +158,6 @@ var args struct { arg.MustParse(&args) ``` -### Priority - -You can use both command line arguments and environmental variables at the same time. -The priority is as follows: command line arguments -> if empty we check environmental variables -> and then we use default values - -```go -var args struct { - Command string `arg:"-c,env:COMMAND" help:"Command to execute" default:"remove"` - File string `arg:"-f,env:FILE_NAME"` -} -arg.MustParse(&args) -``` - ### Default values (before v1.2) ```go @@ -182,6 +169,17 @@ arg.Foo = "abc" arg.MustParse(&args) ``` +### Combining command line options, environment variables, and default values + +You can combine command line arguments, environment variables, and default values. Command line arguments take precedence over environment variables, which take precedence over default values. This means that we check whether a certain option was provided on the command line, then if not, we check for an environment variable (only if an `env` tag was provided), then if none is found, we check for a `default` tag containing a default value. + +```go +var args struct { + Test string `arg:"-t,env:TEST" default:"something"` +} +arg.MustParse(&args) +``` + ### Arguments with multiple values ```go var args struct {