summaryrefslogtreecommitdiff
path: root/parse_test.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2023-07-02 10:07:10 -0400
committerGitHub <[email protected]>2023-07-02 10:07:10 -0400
commit463902ef7d1219df0c6306a3838f4e003da92f91 (patch)
tree2116619d5cabf6e1c43c698f502da42dad1e4df6 /parse_test.go
parente25b4707a7d6c63ff6910c1e1bcb416cb8debfb2 (diff)
parent259c83fd5aeb44fbb67a183cf09b4ca16d9b30e2 (diff)
Merge pull request #222 from IljaN/env-only-args
Support for parameters which can only be passed via env
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 {