Skip to content

feat(cli): make packages argument required for add/remove commands#277

Merged
fengmk2 merged 1 commit intomainfrom
10-30-fix_pm_packages_should_be_required
Oct 30, 2025
Merged

feat(cli): make packages argument required for add/remove commands#277
fengmk2 merged 1 commit intomainfrom
10-30-fix_pm_packages_should_be_required

Conversation

@fengmk2
Copy link
Copy Markdown
Member

@fengmk2 fengmk2 commented Oct 30, 2025

TL;DR

Make package arguments required for add and remove commands in the CLI.

What changed?

  • Added the required = true attribute to the packages argument in both add and remove commands
  • Removed the NoPackagesSpecified error from the error enum as it's no longer needed
  • Removed validation code that checked for empty packages in the add and remove command implementations
  • Removed tests that were checking the empty packages case
  • Updated snap tests to reflect the new required argument behavior
  • Updated command help text in snap tests to show packages as required (<PACKAGES>... instead of [PACKAGES]...)
  • Added a new test case to verify the error when no packages are specified

How to test?

  1. Run vp add without any packages and verify it shows an error about missing required arguments
  2. Run vp remove without any packages and verify it shows an error about missing required arguments
  3. Run the snap tests to verify the updated behavior

Why make this change?

This change improves the CLI interface by making it clearer that package names are required for both add and remove commands. By using Clap's built-in argument validation instead of custom error handling, we get more consistent error messages and better help text. This also simplifies the code by removing unnecessary validation logic and error types.

@fengmk2 fengmk2 changed the title fix(pm): packages should be required feat(cli): make packages argument required for add/remove commands Oct 30, 2025
Copy link
Copy Markdown
Member Author

fengmk2 commented Oct 30, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@fengmk2 fengmk2 self-assigned this Oct 30, 2025
@fengmk2 fengmk2 marked this pull request as ready for review October 30, 2025 03:46
Copilot AI review requested due to automatic review settings October 30, 2025 03:46
Copy link
Copy Markdown
Contributor

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 refactors validation of the add and remove commands by making the packages argument required at the CLI parsing level instead of checking for empty packages within the command execution logic. This shifts the validation responsibility to the argument parser (clap), which provides better error messages and standardized behavior.

  • Moved package validation from runtime to CLI argument parsing by adding #[arg(required = true)]
  • Removed custom NoPackagesSpecified error and related validation code
  • Updated snapshot tests to verify the new error behavior

Reviewed Changes

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

Show a summary per file
File Description
rfcs/add-remove-package-commands.md Removed empty packages check from AddCommand and RemoveCommand execution methods
packages/cli/binding/src/commands/add.rs Removed runtime validation and test for empty packages in AddCommand
packages/cli/binding/src/commands/remove.rs Removed runtime validation and test for empty packages in RemoveCommand
packages/cli/binding/src/cli.rs Added required = true attribute to packages arguments and removed test for empty packages
crates/vite_error/src/lib.rs Removed NoPackagesSpecified error variant
packages/global/snap-tests/command-add-pnpm10/steps.json Added test case for empty packages error and uncommented previously disabled tests
packages/global/snap-tests/command-add-pnpm10/snap.txt Updated snapshot with new CLI help output and error messages showing required argument
packages/global/snap-tests/command-remove-pnpm10/steps.json Added test case for empty packages error
packages/global/snap-tests/command-remove-pnpm10/snap.txt Updated snapshot with new CLI help output and error messages showing required argument
packages/global/snap-tests/command-add-yarn4/snap.txt Updated CLI help output to show required packages argument
packages/global/snap-tests/command-add-pnpm9/snap.txt Updated CLI help output to show required packages argument
packages/global/snap-tests/command-add-npm11/snap.txt Updated CLI help output to show required packages argument
packages/global/snap-tests/command-add-npm10/snap.txt Updated CLI help output to show required packages argument

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fengmk2 fengmk2 merged commit 04d0f12 into main Oct 30, 2025
16 checks passed
Copy link
Copy Markdown
Member Author

fengmk2 commented Oct 30, 2025

Merge activity

@fengmk2 fengmk2 deleted the 10-30-fix_pm_packages_should_be_required branch October 30, 2025 04:46
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.

3 participants