Skip to content

Conversation

@egithinji
Copy link
Member

Some minor improvements to an already-merged PR (#2688) on the task automation via xtask. Main ones being:

  • Adding more explanatory comments about what the xtask package is and what it does
  • Using Clap for CLI arg parsing
  • Using Anyhow for error handling

@egithinji egithinji mentioned this pull request Apr 6, 2025
"install-tools" => install_tools()?,
_ => {
return Err(Box::from(get_help_string(task.as_deref())));
return Err(anyhow!(unrecognized_task_string(task.as_str())));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm surprised it should be necessary with this case? I would have expected Clap to be able to handle it for us?

We can merge this PR now, but could you look into using a Rust enum to represent the available commands? I'm pretty sure Clap can be told that a command line argument must be a valid enum variant — and so it can return an error earlier if people use an unrecognized name.

I think there is an example of what I mean here: https://docs.rs/clap/latest/clap/_cookbook/cargo_example_derive/index.html

We want each xtask (such as install-tools) to become a sub-command.

Copy link
Collaborator

@mgeisler mgeisler left a comment

Choose a reason for hiding this comment

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

Thanks @egithinji! Let's merge this now since it's a nice improvement to what we had before.

@mgeisler mgeisler merged commit 0085748 into google:main Apr 7, 2025
35 checks passed
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