diff options
| author | Pablo Diaz <[email protected]> | 2022-05-21 17:24:45 +0200 |
|---|---|---|
| committer | Ilja Neumann <[email protected]> | 2023-06-03 02:39:56 +0200 |
| commit | c3cac76438ca36d9291d2a26f3ba558ef929d588 (patch) | |
| tree | 8d5d3d069d417d3c7b5f4e6f0d568d9fd11fce44 /usage_test.go | |
| parent | 0280e6e5911d4198f69eae9c876722fdf6149b89 (diff) | |
added tests and fixed usage
Diffstat (limited to 'usage_test.go')
| -rw-r--r-- | usage_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/usage_test.go b/usage_test.go index 69feac2..d5e150f 100644 --- a/usage_test.go +++ b/usage_test.go @@ -646,3 +646,32 @@ Options: p.WriteHelp(&help) assert.Equal(t, expectedHelp[1:], help.String()) } + +func TestFailEnvOnly(t *testing.T) { + expectedUsage := "Usage: AUTH_KEY=auth_key_value example [--arg ARG]" + + expectedHelp := ` +Usage: AUTH_KEY=auth_key_value example [--arg ARG] + +Options: + --arg ARG, -a ARG [env: MY_ARG] + --help, -h display this help and exit + +Environment variables: + AUTH_KEY +` + var args struct { + ArgParam string `arg:"-a,--arg,env:MY_ARG"` + AuthKey string `arg:"-,--,env:AUTH_KEY"` + } + p, err := NewParser(Config{Program: "example"}, &args) + assert.NoError(t, err) + + var help bytes.Buffer + p.WriteHelp(&help) + assert.Equal(t, expectedHelp[1:], help.String()) + + var usage bytes.Buffer + p.WriteUsage(&usage) + assert.Equal(t, expectedUsage, strings.TrimSpace(usage.String())) +} |
