Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@amirabbas-gh
Copy link
Collaborator

📚 Description

🔗 Linked Issue

🧪 Test Plan

📄 Documentation to Update

@vercel
Copy link

vercel bot commented Sep 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
codemod Ignored Ignored Preview Oct 3, 2025 9:13am

@amirabbas-gh amirabbas-gh changed the title Analytics error refactor: add implicit run params parser Sep 18, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 18, 2025

Open in StackBlitz

npm i https://pkg.pr.new/codemod@1783

commit: e7c4e88

@mohebifar mohebifar requested a review from Copilot September 18, 2025 19:19
Copy link
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 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-analytics and --verbose flags 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.

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 {
Copy link

Copilot AI Sep 18, 2025

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.

Suggested change
if cli.disable_analytics || implicit_run_params.unwrap().disable_analytics {
if cli.disable_analytics
|| implicit_run_params
.map_or(false, |params| params.disable_analytics)
{

Copilot uses AI. Check for mistakes.

/// Disable telemetry
#[arg(long, global = true, action = clap::ArgAction::SetTrue)]
#[arg(long, global = true)]
Copy link

Copilot AI Sep 18, 2025

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.

Suggested change
#[arg(long, global = true)]
#[arg(long, global = true, action = clap::ArgAction::SetTrue)]

Copilot uses AI. Check for mistakes.
@mohebifar mohebifar requested a review from Copilot September 19, 2025 23:50
Copy link
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

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.


// 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());
Copy link

Copilot AI Sep 19, 2025

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.

Suggested change
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
});

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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

Comment on lines 226 to 229
let implicit_run_params = Cli::try_parse_from(cli.trailing_args.clone());

if cli.disable_analytics
|| implicit_run_params
Copy link

Copilot AI Sep 19, 2025

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.

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

Copilot uses AI. Check for mistakes.
@amirabbas-gh amirabbas-gh merged commit ca2debb into main Oct 6, 2025
11 checks passed
@amirabbas-gh amirabbas-gh deleted the analytics-error branch October 6, 2025 17:01
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