-
Notifications
You must be signed in to change notification settings - Fork 58
refactor: add implicit run params parser #1783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
commit: |
There was a problem hiding this 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 pull request refactors the implicit run command parameter parsing to simplify the logic and remove manual argument filtering. The changes streamline how CLI arguments are processed when no explicit command is provided.
- Removes manual parsing of
--disable-analyticsand--verboseflags in favor of leveraging clap's built-in parsing - Simplifies argument construction by directly passing all trailing arguments to clap
- Updates the analytics flag handling to use parsed CLI parameters instead of environment variables
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
crates/cli/src/main.rs
Outdated
| if cli.disable_analytics || std::env::var("DISABLE_ANALYTICS") == Ok("true".to_string()) { | ||
| let implicit_run_params = Cli::try_parse_from(cli.trailing_args.clone()); | ||
|
|
||
| if cli.disable_analytics || implicit_run_params.unwrap().disable_analytics { |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unwrap() call will panic if parsing fails. The code should handle the Result properly, either by using pattern matching or a safer method like unwrap_or_default() if there's a sensible default behavior.
| if cli.disable_analytics || implicit_run_params.unwrap().disable_analytics { | |
| if cli.disable_analytics | |
| || implicit_run_params | |
| .map_or(false, |params| params.disable_analytics) | |
| { |
crates/cli/src/main.rs
Outdated
|
|
||
| /// Disable telemetry | ||
| #[arg(long, global = true, action = clap::ArgAction::SetTrue)] | ||
| #[arg(long, global = true)] |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing action = clap::ArgAction::SetTrue from a boolean flag will change its behavior. Boolean flags typically need this action to work correctly with clap, otherwise they may expect a value rather than acting as a toggle.
| #[arg(long, global = true)] | |
| #[arg(long, global = true, action = clap::ArgAction::SetTrue)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
crates/cli/src/main.rs
Outdated
|
|
||
| // Set analytics flag from CLI or check if already set by handle_implicit_run_command | ||
| if cli.disable_analytics || std::env::var("DISABLE_ANALYTICS") == Ok("true".to_string()) { | ||
| let implicit_run_params = Cli::try_parse_from(cli.trailing_args.clone()); |
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Cli::try_parse_from expects the first argument to be the program name, but cli.trailing_args likely doesn't include it. This will cause parsing to fail when the first trailing arg is treated as the program name instead of a command argument. Consider prepending a program name like vec![\"codemod\".to_string()] before the trailing args.
| let implicit_run_params = Cli::try_parse_from(cli.trailing_args.clone()); | |
| let implicit_run_params = Cli::try_parse_from({ | |
| let mut args = vec!["codemod".to_string()]; | |
| args.extend(cli.trailing_args.clone()); | |
| args | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mohebifar this is not true
crates/cli/src/main.rs
Outdated
| let implicit_run_params = Cli::try_parse_from(cli.trailing_args.clone()); | ||
|
|
||
| if cli.disable_analytics | ||
| || implicit_run_params |
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The variable name implicit_run_params is misleading since it contains the full CLI structure, not just run parameters. Consider renaming to implicit_cli_params or parsed_trailing_args to better reflect its content.
| let implicit_run_params = Cli::try_parse_from(cli.trailing_args.clone()); | |
| if cli.disable_analytics | |
| || implicit_run_params | |
| let implicit_cli_params = Cli::try_parse_from(cli.trailing_args.clone()); | |
| if cli.disable_analytics | |
| || implicit_cli_params |
📚 Description
🔗 Linked Issue
🧪 Test Plan
📄 Documentation to Update