Skip to content

fix(cmd): reject unsupported --output values - #481

Open
pcbeingused333 wants to merge 1 commit into
hookdeck:mainfrom
pcbeingused333:fix/validate-output-flag
Open

pcbeingused333 wants to merge 1 commit into
hookdeck:mainfrom
pcbeingused333:fix/validate-output-flag

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #432

Cause: the json-only --output flags were plain StringVars and each command only checked == "json", so any other value (yaml, xml, ...) fell through to the human-readable output with exit code 0.

Fix: a small outputFormatValue (pflag.Value) in pkg/cmd/output_flag.go that accepts "" and json and returns unsupported output format "yaml" (supported: json) otherwise, so cobra rejects it at parse time with a non-zero exit. The ~58 json-only --output registrations now use it (a mechanical one-line change each). listen --output (interactive/compact/quiet) is a different flag and is untouched. Help text is unchanged apart from project list, which said Output format: json and now matches the others.

Test: TestOutputFormatValue (accept/reject) and TestJSONOutputFlagsRejectUnknownFormat, which walks the whole command tree and checks that every command using the new flag value rejects yaml and accepts json. go test ./pkg/cmd/ passes, go vet and gofmt clean.

This change was prepared with AI assistance (Claude Code).

🤖 Generated with Claude Code

Commands with a json-only --output flag silently fell back to the
human-readable output for any other value (e.g. yaml) and exited 0.
Validate the value when the flag is parsed and name the supported one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsupported --output values are silently ignored and exit 0

1 participant