Repository navigation
Description
The two compliance flags are registered as StringVar, so pflag requires a
value — but the value is never read. The mode is decided by Changed(). The
result is that the flag eats the next argv token, and the documented JSON path
silently emits a human table.
The registration
cmd/validate.go:53-54:
validateCmd.Flags().StringVar(&validateComplianceMode, "nist-800-171", "", "Validate NIST 800-171 compliance")
validateCmd.Flags().StringVar(&validateComplianceMode, "nist-800-53", "", "Validate NIST 800-53 compliance (low, moderate, high)")No NoOptDefVal, so a value is mandatory. And validateComplianceMode has
exactly two references in non-test code — those two lines. The actual decision is
at cmd/validate.go:70-72 via cmd.Flags().Changed(...), which ignores the
value entirely.
For --nist-800-53 a value is meaningful (low|moderate|high). For
--nist-800-171 there is nothing to supply, yet one is demanded.
Three consequences, all verified against the built binary
1. The command's own documented Example fails.
$ spawn validate --nist-800-171
flag needs an argument: --nist-800-171
That exact invocation appears as an Example at cmd/validate.go:37 and as the
command's own error-message remedy at :82:
compliance mode required: use --nist-800-171 or --nist-800-53=<low|moderate|high>
So the fix the tool prints does not work either.
2. -o json is swallowed and the output is a table — exit 0.
$ spawn validate --nist-800-171 -o json
pflag consumes -o as the flag's value, leaving json as a positional
argument. The command runs, scans, and prints the table report. A script
parsing that output gets human-formatted text with a success exit code — the
worst failure shape, because nothing signals it.
3. The --instance-id Example is doubly broken.
cmd/validate.go:40 documents
spawn validate --instance-id i-0abc123 --nist-800-171. It fails the same arity
way, and even once parsed, cmd/validate.go:109 returns
"single instance validation not yet implemented".
Suggested
Make the flags' arity match how they are consumed:
--nist-800-171takes no value: register it asBoolVar, or keepStringVar
withNoOptDefValset so the value is optional.--nist-800-53keeps a required value and should validate it against
low|moderate|highrather than being read only viaChanged()— today
--nist-800-53=bananais accepted.- Fix the two Examples and the error-message remedy so the printed instruction
works (see The tool prints instructions that do not work:spawn instances liston a cost-leak path,spawn fsx createexiting 0, and five doc paths that never existed #806 — the gate proposed there would catch the remedy). - Decide what
--instance-idshould do, or stop advertising it in an Example
while it returns "not yet implemented".
A gate worth having: for every flag registered as StringVar, either the
variable is read somewhere, or NoOptDefVal is set. A string flag whose value is
never read but is still mandatory will always swallow the following argument, and
that is invisible until someone combines it with another flag.
Activity
Fix the compliance flags' arity, and gate the class