Skip to content

fix: bind prune and version flags to correct cobra command#430

Open
rishi-jat wants to merge 1 commit intomodelpack:mainfrom
rishi-jat:fix/prune-version-flag-binding
Open

fix: bind prune and version flags to correct cobra command#430
rishi-jat wants to merge 1 commit intomodelpack:mainfrom
rishi-jat:fix/prune-version-flag-binding

Conversation

@rishi-jat
Copy link
Contributor

Summary

Fix incorrect flag registration in prune and version commands.

Both commands were binding flags using rmCmd.Flags(), causing:

  • prune flags to be attached to rm
  • prune --dry-run not behaving as expected
  • unintended flags appearing under rm

Changes

  • Use pruneCmd.Flags() in cmd/prune.go
  • Use versionCmd.Flags() in cmd/version.go

Signed-off-by: Rishi Jat <rishijat098@gmail.com>
Copilot AI review requested due to automatic review settings February 27, 2026 09:58
@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 resolves critical flag binding issues within the prune and version commands. Previously, both commands mistakenly registered their flags with the rm command, causing functional errors like prune --dry-run not working as expected and polluting the rm command's help output with irrelevant flags. The changes ensure that each command's flags are correctly associated with its own cobra.Command instance, thereby restoring proper command-line interface behavior and improving user experience.

Highlights

  • Flag Binding Correction: The pull request addresses an issue where prune and version commands were incorrectly binding their flags to rmCmd.Flags(), leading to misbehavior of prune --dry-run and unintended flags appearing under the rm command.
  • prune Command Fix: The prune command's flags are now correctly bound using pruneCmd.Flags(), ensuring its options function as intended.
  • version Command Fix: The version command's flags are now correctly bound using versionCmd.Flags(), resolving incorrect flag associations.
Changelog
  • cmd/prune.go
    • Changed flags := rmCmd.Flags() to flags := pruneCmd.Flags() to correctly bind flags.
  • cmd/version.go
    • Changed flags := rmCmd.Flags() to flags := versionCmd.Flags() to correctly bind flags.
Activity
  • No activity (comments, reviews, etc.) was found for this pull request.
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.

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 fixes an issue where flags for the prune and version commands were bound to the wrong command. The changes are correct. I've added one suggestion on cmd/version.go to remove some redundant code. As a minor note, you may also want to update the error message on line 52 of cmd/prune.go in a follow-up, as it seems to be a copy-paste from another command and is outside the scope of this PR's changes.

Comment on lines +42 to 45
flags := versionCmd.Flags()

if err := viper.BindPFlags(flags); err != nil {
panic(fmt.Errorf("bind version flags to viper: %w", err))

Choose a reason for hiding this comment

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

medium

Since the version command has no flags defined, versionCmd.Flags() returns an empty flag set. The subsequent call to viper.BindPFlags is therefore a no-op. This block of code is redundant. For better code clarity, consider removing the entire init function as it currently has no effect.

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 fixes a bug where the prune and version commands were incorrectly registering their flags to the rm command instead of their own commands. This was caused by using rmCmd.Flags() instead of the respective command's Flags() method in their init functions.

Changes:

  • Fixed prune command to use pruneCmd.Flags() instead of rmCmd.Flags()
  • Fixed version command to use versionCmd.Flags() instead of rmCmd.Flags()

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cmd/prune.go Changed flag registration from rmCmd.Flags() to pruneCmd.Flags() to correctly bind prune-specific flags
cmd/version.go Changed flag registration from rmCmd.Flags() to versionCmd.Flags() to correctly bind version-specific flags

💡 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