summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorJames Shubin <[email protected]>2024-02-28 22:29:16 -0500
committerJames Shubin <[email protected]>2024-02-28 22:29:16 -0500
commit84ddf1d244f4bbe299f082e1c880c34831f49c57 (patch)
tree35bf9357a03c10737c6b37aeb1ad39d023b6f517 /README.md
parentbf629a16cbe505e81b6347813a918770a3b727df (diff)
add an example for environment vars with arg names
If you want to specify both of these, and if they should have different names, then this shows you how it can be done.
Diffstat (limited to 'README.md')
-rw-r--r--README.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/README.md b/README.md
index f105b17..3ea28cc 100644
--- a/README.md
+++ b/README.md
@@ -120,6 +120,23 @@ $ WORKERS='1,99' ./example
Workers: [1 99]
```
+You can also have an environment variable that doesn't match the arg name:
+
+```go
+var args struct {
+ Workers int `arg:"--count,env:NUM_WORKERS"`
+}
+arg.MustParse(&args)
+fmt.Println("Workers:", args.Workers)
+```
+
+```
+$ NUM_WORKERS=6 ./example
+Workers: 6
+$ NUM_WORKERS=6 ./example --count 4
+Workers: 4
+```
+
### Usage strings
```go
var args struct {