summaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go32
1 files changed, 29 insertions, 3 deletions
diff --git a/example_test.go b/example_test.go
index acfacad..6216e18 100644
--- a/example_test.go
+++ b/example_test.go
@@ -499,12 +499,12 @@ func Example_allSupportedTypes() {
func Example_envVarOnly() {
os.Args = split("./example")
- _ = os.Setenv("NUM_WORKERS", "my_key")
+ _ = os.Setenv("AUTH_KEY", "my_key")
- defer os.Unsetenv("NUM_WORKERS")
+ defer os.Unsetenv("AUTH_KEY")
var args struct {
- AuthKey string `arg:"-,--,env:NUM_WORKERS"`
+ AuthKey string `arg:"-,--,env:AUTH_KEY"`
}
MustParse(&args)
@@ -512,3 +512,29 @@ func Example_envVarOnly() {
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
+}