summaryrefslogtreecommitdiff
path: root/parse_test.go
diff options
context:
space:
mode:
authorIlja Neumann <[email protected]>2023-06-03 12:47:47 +0200
committerIlja Neumann <[email protected]>2023-06-03 12:47:47 +0200
commit18623d869bfb7aa7b87eda2c8dc7d1bf6149f316 (patch)
tree47bc965aac8847cb35791ea5e79871242b9df926 /parse_test.go
parentb928a1839ae3502fc6fef8d7743dd78f2c772c8a (diff)
help,usage and error messages and tests
Diffstat (limited to 'parse_test.go')
-rw-r--r--parse_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/parse_test.go b/parse_test.go
index d368b17..77a034f 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -227,6 +227,14 @@ func TestRequiredWithEnv(t *testing.T) {
require.Error(t, err, "--foo is required (or environment variable FOO)")
}
+func TestRequiredWithEnvOnly(t *testing.T) {
+ var args struct {
+ Foo string `arg:"required,--,-,env:FOO"`
+ }
+ _, err := parseWithEnv("", []string{}, &args)
+ require.Error(t, err, "environment variable FOO is required")
+}
+
func TestShortFlag(t *testing.T) {
var args struct {
Foo string `arg:"-f"`
@@ -845,6 +853,24 @@ func TestDefaultValuesIgnored(t *testing.T) {
assert.Equal(t, "", args.Foo)
}
+func TestRequiredEnvironmentOnlyVariableIsMissing(t *testing.T) {
+ var args struct {
+ Foo string `arg:"required,--,env:FOO"`
+ }
+
+ _, err := parseWithEnv("", []string{""}, &args)
+ assert.Error(t, err)
+}
+
+func TestOptionalEnvironmentOnlyVariable(t *testing.T) {
+ var args struct {
+ Foo string `arg:"env:FOO"`
+ }
+
+ _, err := parseWithEnv("", []string{}, &args)
+ assert.NoError(t, err)
+}
+
func TestEnvironmentVariableInSubcommandIgnored(t *testing.T) {
var args struct {
Sub *struct {