diff options
| author | Alex Flint <[email protected]> | 2023-07-02 10:07:10 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-02 10:07:10 -0400 |
| commit | 463902ef7d1219df0c6306a3838f4e003da92f91 (patch) | |
| tree | 2116619d5cabf6e1c43c698f502da42dad1e4df6 /example_test.go | |
| parent | e25b4707a7d6c63ff6910c1e1bcb416cb8debfb2 (diff) | |
| parent | 259c83fd5aeb44fbb67a183cf09b4ca16d9b30e2 (diff) | |
Merge pull request #222 from IljaN/env-only-args
Support for parameters which can only be passed via env
Diffstat (limited to 'example_test.go')
| -rw-r--r-- | example_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go index 5272393..4bd7632 100644 --- a/example_test.go +++ b/example_test.go @@ -496,3 +496,45 @@ func Example_allSupportedTypes() { // output: } + +func Example_envVarOnly() { + os.Args = split("./example") + _ = os.Setenv("AUTH_KEY", "my_key") + + defer os.Unsetenv("AUTH_KEY") + + var args struct { + AuthKey string `arg:"--,env:AUTH_KEY"` + } + + MustParse(&args) + + fmt.Println(args.AuthKey) + // output: my_key +} + +func Example_envVarOnlyShouldIgnoreFlag() { + os.Args = split("./example --=my_key") + + var args struct { + AuthKey string `arg:"--,env:AUTH_KEY"` + } + + err := Parse(&args) + + fmt.Println(err) + // output: unknown argument --=my_key +} + +func Example_envVarOnlyShouldIgnoreShortFlag() { + os.Args = split("./example -=my_key") + + var args struct { + AuthKey string `arg:"--,env:AUTH_KEY"` + } + + err := Parse(&args) + + fmt.Println(err) + // output: unknown argument -=my_key +} |
