fix: accept boolean flag values written with a space#1037
Conversation
"kosli attest generic Dockerfile --compliant false" failed with "accepts at most 1 arg(s), received 2". pflag's NoOptDefVal makes a boolean flag never consume the next token, so "false" was left behind as a positional argument. The bare "--compliant" form and the space form are gated by that same single field in opposite directions, so no custom pflag.Value type can fix it, because the consume-or-not decision is made before Set() is ever called on the value. Normalize the argument slice before pflag sees it, rewriting the space form into the "=" form for boolean flags only. Both places that feed args to cobra do this: innerMain for the normal path, and getMultiOpts for the multi-host path, where the stray positional previously emptied MultiOpts and silently downgraded a multi-host call to a single host. The golden test harness normalizes too, so tests exercise the same args path as the real CLI instead of asserting the pre-fix behaviour. Deliberately left alone, each still failing loudly with the link to the boolean flags FAQ: grouped shorthands such as "-qC false", literals pflag accepts via "=" but Kosli does not document such as "TRUE" and "1", and anything following a "--" terminator. Refs kosli-dev/server#6235
|
Claude finished @JonJagger's task in 2m 28s —— View job Review: accept boolean flag values written with a space
Verdict: LGTM. This is a careful, well-reasoned fix. The core insight in the PR description — that pflag's Static analysis
What's good
Observations (non-blocking)
No changes requested. Nicely done. |
Review of #1037 spotted an input the rewrite reads differently from pflag and that nothing recorded: "--name --compliant false". pflag gives --name the value "--compliant" and leaves "false" positional, whereas the rewrite sees a space-form boolean and joins it. Left as is. It sits in the same family as the already-accepted positional named "true", and telling the two apart would mean tracking which tokens pflag consumes as values, turning a token pre-pass into a second parser. What was missing was the boundary being written down, so a later reader does not rediscover it as a bug. The doc comment now names the rewrite as positional and lists both inputs, and a test pins the behaviour the way the sibling ambiguity already is. Comment and test only, no behaviour change.
"kosli attest generic Dockerfile --compliant false" failed with
"accepts at most 1 arg(s), received 2". pflag's NoOptDefVal makes a
boolean flag never consume the next token, so "false" was left behind
as a positional argument. The bare "--compliant" form and the space
form are gated by that same single field in opposite directions, so no
custom pflag.Value type can fix it, because the consume-or-not decision
is made before Set() is ever called on the value.
Normalize the argument slice before pflag sees it, rewriting the space
form into the "=" form for boolean flags only. Both places that feed
args to cobra do this: innerMain for the normal path, and getMultiOpts
for the multi-host path, where the stray positional previously emptied
MultiOpts and silently downgraded a multi-host call to a single host.
The golden test harness normalizes too, so tests exercise the same args
path as the real CLI instead of asserting the pre-fix behaviour.
Deliberately left alone, each still failing loudly with the link to the
boolean flags FAQ: grouped shorthands such as "-qC false", literals
pflag accepts via "=" but Kosli does not document such as "TRUE" and
"1", and anything following a "--" terminator.
Refs kosli-dev/server#6235