Skip to content
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

Feature request: Add a way to *extend* an existing Cmd with syntax very similar to cmd! #96

Open
RalfJung opened this issue Aug 9, 2024 · 0 comments

Comments

@RalfJung
Copy link

RalfJung commented Aug 9, 2024

The cmd! macro is great: commands are quickly written, very readable, and whitespace-safe. However, when the shell scripting becomes a bit more complicated, one quickly hits a frustrating limitation: I have a lot of cmd! invocations in my script that are very similar, but there is no good way to abstract the commonalities into a helper function. The problem is that the cmd! macro can be used only exactly once per command, so it's not possible to have a helper prepare a Cmd value with all the things that are common across my script and then later conveniently add more arguments to it.

In my case, what I'd like to be able to do looks roughly like this:

fn cargo(&self, subcommand: &str) -> Cmd {
  // ...
  cmd!("cargo +{toolchain} {subcommand} {cargo_extra_flags...} --manifest-path={manifest_path}")
    .env(...)
}

fn other_function(&self, ...) {
  extend_cmd!(
    self.cargo("build"),
    "--bins --tests {quiet_flag...} {args...}",
  ).run()?;
}

But currently, I have to instead either repeat the cargo +{toolchain} {subcommand} {cargo_extra_flags...} --manifest-path={manifest_path} part everywhere or write

fn other_function(&self, ...) {
  let cmd = self.cargo("build")
    .args(&["--bins", "--tests"])
    .args(quiet_flag)
    .args(args)
}

which is a lot less readable than what one can do with cmd!.

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

No branches or pull requests

1 participant