From 3d59e5e89e775b1d33a451aca6aa4bda4fbad500 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Fri, 20 Aug 2021 19:52:48 -0700 Subject: bump go-scalar to v1.1 and add documentation about supported types --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 48fa2f0..229a9df 100644 --- a/README.md +++ b/README.md @@ -308,6 +308,22 @@ func main() { As usual, any field tagged with `arg:"-"` is ignored. +### Supported types + +The following types may be used as arguments: +- built-in integer types: `int, int8, int16, int32, int64, byte, rune` +- built-in floating point types: `float32, float64` +- strings +- booleans +- URLs represented as `url.URL` +- time durations represented as `time.Duration` +- email addresses represented as `mail.Address` +- MAC addresses represented as `net.HardwareAddr` +- pointers to any of the above +- slices of any of the above +- maps using any of the above as keys and values +- any type that implements `encoding.TextUnmarshaler` + ### Custom parsing Implement `encoding.TextUnmarshaler` to define your own parsing logic. -- cgit v1.2.3 From b157e8d10a29fcea34b33988776848a322ef69dc Mon Sep 17 00:00:00 2001 From: evgenv123 <83824538+evgenv123@users.noreply.github.com> Date: Sat, 18 Sep 2021 22:23:26 +0700 Subject: Update README.md Hi! As a first-time user of your great package I got a little bit confused on using command line args and env vars together, so it took me some time to make testing and I propose to save this time for other people by adding relevant edits to README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 229a9df..855c02e 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,19 @@ 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 -- cgit v1.2.3 From 0f0b4b5c3f9dfab413c3127830b869bc7d4b0e27 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Sat, 18 Sep 2021 08:50:33 -0700 Subject: Update README.md --- README.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 855c02e..dab2996 100644 --- a/README.md +++ b/README.md @@ -158,27 +158,25 @@ 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 +### Default values (before v1.2) ```go var args struct { - Command string `arg:"-c,env:COMMAND" help:"Command to execute" default:"remove"` - File string `arg:"-f,env:FILE_NAME"` + Foo string + Bar bool } +arg.Foo = "abc" arg.MustParse(&args) ``` -### Default values (before v1.2) +### 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 { - Foo string - Bar bool + Test string `arg:"-t,env:TEST" default:"something"` } -arg.Foo = "abc" arg.MustParse(&args) ``` -- cgit v1.2.3