fix(cli): reject invalid arguments on plugin, plugin install, and convert - #349
Open
kayemkim wants to merge 1 commit into
Open
fix(cli): reject invalid arguments on plugin, plugin install, and convert#349kayemkim wants to merge 1 commit into
kayemkim wants to merge 1 commit into
Conversation
…vert Fixes apache#345. Three commands accepted invalid invocations and exited 0: - plugin install and convert declared no Args validator, so cobra accepted arbitrary positional arguments (same root cause as apache#334). install now takes at most one argument and requires exactly one of the plugin name or --all; convert is flag-only and takes none. - The plugin parent command needed a different fix: without a RunE it is not runnable, cobra returns flag.ErrHelp before ever reaching ValidateArgs, and both a bare "ossie plugin" and an unknown subcommand printed help and exited 0. It now has Args: NoArgs plus a RunE that reports an error, which puts validation back in the execution path. Tests exercise the real entry point via rootCmd.Execute() rather than cmd.ValidateArgs(), which passes on a non-runnable parent while the CLI still exits 0. A recursive walk over rootCmd.Commands() asserts every command declares an Args validator and every parent is runnable, so the next command added without validation fails the suite. Signed-off-by: km <kayemkim@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
All five reproductions from #345 now exit non-zero with usage shown:
As the issue's cause analysis lays out, this took two different fixes:
plugin installandconvertsimply lacked anArgsvalidator.installnow takes at most one positional argument and requires exactly one of the plugin name or--all(soinstall --all foois also rejected);convertis flag-only and takes none.pluginparent had to become runnable first: without aRun/RunE, cobra bails out withflag.ErrHelpbefore reachingValidateArgs, soArgsalone is dead code there. It now has aRunEthat returns an error for a bareossie plugin, and once the command is runnable,NoArgsproduces the "unknown command" error for a typo'd subcommand.Tests follow the issue's suggestion on both points. They drive the real entry point through
rootCmd.SetArgs()/Execute(), since a directValidateArgscall passes on the non-runnable parent while the CLI still exits 0; covered are the five reproductions, the valid invocations, and the help paths (--help,-h, andhelp pluginall still exit 0). A second test walksrootCmd.Commands()recursively and fails if any command lacks anArgsvalidator or any parent is not runnable, so the next command added without validation fails the suite.The "stubs print not yet implemented and exit 0" part at the end of the issue is left out here, since it's marked there as likely a separate issue.
Related Issues
Fixes #345.
Checklist
Specification
core-spec/and follow the existing structureOntology
ontology/are consistent with spec changesConverters
converters/is updated to reflect spec or ontology changesValidation
validation/are updated if the spec changedDocumentation
docs/is updated to reflect any user-facing changesCONTRIBUTING.mdis updated if the contribution process changedExamples
examples/are added or updated for any new spec constructs or converter supportTests
pytest/ CI green)Compliance