diff --git a/executor.go b/executor.go index 8d5e1ce..29e3677 100644 --- a/executor.go +++ b/executor.go @@ -449,7 +449,9 @@ func (e *Executor) parseTaskFlagsIntoMap(taskName string, flags []string) map[st flagValErrMsg := fmt.Sprintf("The type for the `%s` flag is `%s`. Please use `%s`", key, taskFlag.ValueType, flagTypeToGetter[taskFlag.ValueType]) // Bare boolean flags (e.g. --dry-run without =value) mean true. - if val == "" && taskFlag.ValueType == BoolTypeFlag { + // len(splitFlag)==1 means no "=" was present; len(splitFlag)==2 with + // empty val means "--flag=" which is an explicit empty value, not bare. + if val == "" && len(splitFlag) == 1 && taskFlag.ValueType == BoolTypeFlag { val = "true" } diff --git a/executor_internal_test.go b/executor_internal_test.go index de3bdd1..68c8250 100644 --- a/executor_internal_test.go +++ b/executor_internal_test.go @@ -151,6 +151,11 @@ func TestParseTaskOptionsListToMap(t *testing.T) { flagArgs: []string{"-f"}, expectedFlagFVal: boolPtr(true), }, + { + description: "Explicit empty bool flag (--flag=) should not default to true", + flagArgs: []string{"-f="}, + expectFlagFNil: true, + }, { description: "Should store Default values for all flags and Value nil when no args are passed", flagArgs: []string{},