summaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorPablo Diaz <[email protected]>2022-05-21 17:24:45 +0200
committerIlja Neumann <[email protected]>2023-06-03 02:39:56 +0200
commitc3cac76438ca36d9291d2a26f3ba558ef929d588 (patch)
tree8d5d3d069d417d3c7b5f4e6f0d568d9fd11fce44 /example_test.go
parent0280e6e5911d4198f69eae9c876722fdf6149b89 (diff)
added tests and fixed usage
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
+}