fix: remove UnknownFlags whitelist from subcommands#432
fix: remove UnknownFlags whitelist from subcommands#432rishi-jat wants to merge 1 commit intomodelpack:mainfrom
Conversation
Signed-off-by: Rishi Jat <rishijat098@gmail.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the command-line interface's behavior by implementing stricter flag parsing across all subcommands. The removal of the Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
/cc @chlins |
There was a problem hiding this comment.
Code Review
This pull request correctly removes the whitelisting of unknown flags from various subcommands, which is a great improvement for the command-line interface's robustness and user experience. By erroring on unknown flags, it will help users catch typos and incorrect usage.
While reviewing, I noticed a few areas for improvement, some of which are in files not modified by this PR. I'm including them here for completeness:
- Critical Bug in
cmd/prune.go: There seems to be a copy-paste error incmd/prune.go. In theinit()function,rmCmd.Flags()is used instead ofpruneCmd.Flags(). This means that flags intended for theprunecommand (like--dry-run) are being incorrectly added to thermcommand. This should be fixed to ensure theprunecommand works as expected. - Inconsistency in
cmd/root.go: The root command incmd/root.gostill hasFParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}. For consistency with the changes in this PR, you might consider removing this from the root command as well, so that unknown global flags also produce an error. - Minor issue in
cmd/version.go: A similar, but less harmful, copy-paste error exists incmd/version.go'sinit()function, wherermCmd.Flags()is also used.
| Args: cobra.ExactArgs(1), | ||
| DisableAutoGenTag: true, | ||
| SilenceUsage: true, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return nil | ||
| }, |
There was a problem hiding this comment.
The modelfile command acts as a command group for subcommands like generate. As such, it shouldn't have its own execution logic or argument requirements that could lead to confusing behavior. Currently, modctl modelfile foo is a valid command that does nothing, which is likely not the intended behavior.
To make this behave like a standard command group, I suggest removing the Args and RunE fields. This way, if modctl modelfile is run without a subcommand, cobra will automatically print the help message, which is more user-friendly.
| Args: cobra.ExactArgs(1), | |
| DisableAutoGenTag: true, | |
| SilenceUsage: true, | |
| RunE: func(cmd *cobra.Command, args []string) error { | |
| return nil | |
| }, | |
| DisableAutoGenTag: true, | |
| SilenceUsage: true |
| SilenceUsage: true, | ||
| FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, | ||
| Use: "version", | ||
| Short: "A command line tool for modctl version", |
There was a problem hiding this comment.
The version command does not use any arguments. To prevent users from providing arguments that are silently ignored, it's a good practice to explicitly disallow them by setting Args: cobra.NoArgs.
| Short: "A command line tool for modctl version", | |
| Short: "A command line tool for modctl version", | |
| Args: cobra.NoArgs, |
There was a problem hiding this comment.
Pull request overview
This PR improves flag validation for CLI subcommands by removing the FParseErrWhitelist setting that previously allowed unknown flags to be silently ignored. This change helps users catch typos and incorrect flag usage by returning errors for unrecognized flags.
Changes:
- Removed
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}from all 17 subcommands - Reformatted field alignment in cobra.Command structs for consistency
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/attach.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/build.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/extract.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/fetch.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/inspect.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/list.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/login.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/logout.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/prune.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/pull.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/push.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/rm.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/tag.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/upload.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/version.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/modelfile/modelfile.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
| cmd/modelfile/generate.go | Removed UnknownFlags whitelist, subcommand will now validate flags strictly |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Remove
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}from all subcommands.
Previously, unknown flags were silently ignored, which could hide user typos
and mask incorrect flag usage.
Subcommands now return an error for unknown flags.