Skip to content

fix: remove UnknownFlags whitelist from subcommands#432

Open
rishi-jat wants to merge 1 commit intomodelpack:mainfrom
rishi-jat:fix/remove-unknownflags-from-subcommands
Open

fix: remove UnknownFlags whitelist from subcommands#432
rishi-jat wants to merge 1 commit intomodelpack:mainfrom
rishi-jat:fix/remove-unknownflags-from-subcommands

Conversation

@rishi-jat
Copy link
Contributor

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.

Signed-off-by: Rishi Jat <rishijat098@gmail.com>
Copilot AI review requested due to automatic review settings February 27, 2026 12:30
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 UnknownFlags whitelist ensures that the application will now explicitly report errors for unrecognized flags. This enhancement aims to improve the user experience by preventing silent failures due to typos or incorrect command arguments, thereby making the CLI more robust and user-friendly.

Highlights

  • Stricter Flag Parsing: The FParseErrWhitelist configuration, which previously allowed unknown flags to be silently ignored, has been removed from all subcommands. This change means that any unrecognized flags will now result in an error.
  • Enhanced User Feedback: By disallowing unknown flags, the command-line interface will provide immediate feedback to users, helping them identify typos or incorrect flag usage more effectively, rather than silently proceeding with potentially unintended behavior.
Changelog
  • cmd/attach.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/build.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/extract.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/fetch.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/inspect.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/list.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/login.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/logout.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/modelfile/generate.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/modelfile/modelfile.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/prune.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/pull.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/push.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/rm.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/tag.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/upload.go
    • Removed FParseErrWhitelist for unknown flags.
  • cmd/version.go
    • Removed FParseErrWhitelist for unknown flags.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@rishi-jat
Copy link
Contributor Author

/cc @chlins

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in cmd/prune.go. In the init() function, rmCmd.Flags() is used instead of pruneCmd.Flags(). This means that flags intended for the prune command (like --dry-run) are being incorrectly added to the rm command. This should be fixed to ensure the prune command works as expected.
  • Inconsistency in cmd/root.go: The root command in cmd/root.go still has FParseErrWhitelist: 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 in cmd/version.go's init() function, where rmCmd.Flags() is also used.

Comment on lines +28 to 33
Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return nil
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
Short: "A command line tool for modctl version",
Short: "A command line tool for modctl version",
Args: cobra.NoArgs,

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

2 participants