cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Possibility to combine multiple aliases

Open eduardonunesp opened this issue 2 years ago • 2 comments

Problem

Right now when run multiple alias together from .cargo/config.toml the [alias] its considered the argument of the first alias as a parameter not another alias.

For instance: (disclaimer the build and run it's just an example, I'm know that run already builds the project)

[alias]
b  = "build"
r  = "run"
br = "b r"

it will return an error:

$ cargo br
error: unexpected argument 'r' found

Because it's considering the r some argument for the cargo build

Proposed Solution

The proposal is to allow a checking for combination of the multiple aliases in just one alias, so it's be useful to generate sub commands that can be combined together on a combo of commands, for instance:

[alias]
create-db  = "sqlx database create ..." 
migrate-db = "sqlx migrate run ..."
setup-db   = "create-db migrate-db"

Notes

In order to make the implementation easier, another way to create the alias can be added, so it will avoid unexpected collisions with the previous implementations or previous commands that already exists, for instance:

[alias]
create-db  = "sqlx database create ..." 
migrate-db = "sqlx migrate run ..."
setup-db   =  { alias = ["db-create", "migrate-db"] }

This is just an sample, maybe is a better way to concat those multiple commands

eduardonunesp avatar Nov 09 '23 16:11 eduardonunesp

There is https://github.com/rust-lang/cargo/issues/6575 that should cover this scenario with a bit more extensibility. For now, I would recommend some patterns like cargo-xtask. Cargo the project itself also adopts it.

weihanglo avatar Nov 09 '23 16:11 weihanglo

This invites a lot of one off design work to implement this feature (serial vs parallel, fail fast vs accumulate errors, on-fail or always-run actions), that I think we should focus the design work on #6575 which could encompass all of this without having two separate bespoke systems.

As such I'm proposed to the Cargo team we close this in favor of #6575.

epage avatar Apr 29 '24 15:04 epage

Second.

weihanglo avatar Aug 09 '24 17:08 weihanglo