From afbd417c1e927fc23dd0fa135aa2b46df1e42131 Mon Sep 17 00:00:00 2001 From: Jesse Chen Date: Wed, 27 May 2026 15:19:11 -0700 Subject: [PATCH] fix: distinguish bare bool flags from explicit empty value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --flag (bare, no =) → true --flag= (explicit empty) → falls through to default Prevents --flag=$UNSET_VAR from silently being treated as true. Co-Authored-By: Claude Opus 4.6 (1M context) --- executor.go | 4 +++- executor_internal_test.go | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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{},