Skip to content

Commit

Permalink
Merge pull request #237 from purpleidea/feat/env-docs
Browse files Browse the repository at this point in the history
add an example for environment vars with arg names
  • Loading branch information
alexflint authored Jun 30, 2024
2 parents 177b844 + 84ddf1d commit 56ee7c9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 56ee7c9

Please sign in to comment.