Skip to content

refactor: replace deprecated clap derive attributes with command and arg#3466

Open
yan-ace62 wants to merge 1 commit intoyouki-dev:mainfrom
yan-ace62:main
Open

refactor: replace deprecated clap derive attributes with command and arg#3466
yan-ace62 wants to merge 1 commit intoyouki-dev:mainfrom
yan-ace62:main

Conversation

@yan-ace62
Copy link
Copy Markdown
Contributor

Updated the CLI definition to use the modern #[command] and #[arg] attributes, as the legacy #[clap] attributes are now deprecated in clap v4.

Description

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test updates
  • CI/CD related changes
  • Other (please describe):

Testing

  • Added new unit tests
  • Added new integration tests
  • Ran existing test suite
  • Tested manually (please provide steps)

Related Issues

Fixes #

Additional Context

@nayuta723 nayuta723 added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Mar 22, 2026
@yan-ace62 yan-ace62 closed this Mar 28, 2026
@yan-ace62 yan-ace62 reopened this Mar 28, 2026
Copy link
Copy Markdown
Member

@saku3 saku3 left a comment

Choose a reason for hiding this comment

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

Thank you for the changes.

Could you please resolve the conflicts?

Could you share the documentation you referred to for the migration, such as the migration guide?

Would you also mind explaining the following points?

  • The rationale for splitting #[clap(...)] into #[arg(...)] and #[command(...)]
  • The change related to number_of_values
  • Why allow_hyphen_values was removed
  • How you verified the behavior of the changes

Sorry for the many questions.

Updated the CLI definition to use the modern #[command] and #[arg] attributes, as the legacy #[clap] attributes are now deprecated in clap v4.

Signed-off-by: Yan Wen <yan_ace62@126.com>
@yan-ace62
Copy link
Copy Markdown
Contributor Author

Thank you for the changes.

Could you please resolve the conflicts?

Could you share the documentation you referred to for the migration, such as the migration guide?

Would you also mind explaining the following points?

  • The rationale for splitting #[clap(...)] into #[arg(...)] and #[command(...)]
  • The change related to number_of_values
  • Why allow_hyphen_values was removed
  • How you verified the behavior of the changes

Sorry for the many questions.

Hi, thanks for the review! I have addressed the conflicts and here are the details regarding the migration and your questions:

Migration Documentation:
I primarily followed the official v4 migration guide: clap v4.0.0 Migrating Guide.

  1. Rationale for splitting #[clap(...)] into #[arg(...)] and #[command(...)]
    According to the official changelog, the structopt and clap attributes were deprecated in favor of more specific ones (command, arg, and value). This change was made to "open the door for more features and clarify the relationship to the builder" (#1807, #4180). It helps distinguish whether an attribute applies to the command-level configuration or a specific argument.

  2. The change related to number_of_values
    The migration guide notes that Arg::number_of_values has been replaced by Arg::num_args. This is intended to "clarify semantic differences" regarding how many arguments a flag or option is expected to take.

  3. Why allow_hyphen_values was removed (from Command)
    Command::allow_hyphen_values was deprecated in favor of Arg::allow_hyphen_values. The goal was to "make it clearer which arg it is meant to apply to" (#4187), moving the control from a global command setting to a per-argument setting.

  4. How the behavior of the changes was verified
    To verify the changes, I ran the existing integration tests in the tests/ directory. I haven't performed additional manual verification beyond the scope of these automated tests, but they currently pass as expected.

Please let me know if you have any further questions or if there are other areas I should look into!

@utam0k
Copy link
Copy Markdown
Member

utam0k commented Apr 11, 2026

Is this a breaking change?

@yan-ace62
Copy link
Copy Markdown
Contributor Author

Is this a breaking change?

"This PR is largely not a breaking change, with one potential exception.
The main update involves migrating deprecated clap derive attributes to the current command and arg attributes, which preserves all existing functionality and public-facing interfaces.
The only potential breaking change is the renaming of enum SubCommand to YoukiSubCommand. I made this change because the original name was too ambiguous, and YoukiSubCommand better reflects its intent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants