Skip to content

danreeves/cargo-cmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cargo-cmd

crates.io version build status docs.rs docs license

Alias any shell command in your Cargo.toml. It's like npm scripts, but for cargo.

Installation

cargo install cargo-cmd

Usage

You can define your commands in Cargo.toml under the [package.metadata.commands] table, like so:

[package.metadata.commands]
greet = "echo 'Hello, planet!'"

Now you can run cargo cmd greet:

$ cargo cmd greet
> echo 'Hello, planet!'
Hello, planet!

Advanced use

Passing arguments

It's possible to pass arguments into your command by passing them directly to cargo cmd.

[package.metadata.commands]
echo = "echo"
$ cargo cmd echo 'Hello, planet!'
> echo 'Hello, planet!'
Hello, planet!

Pre and Post commands

You are able to set up commands to run before and after your command by prefixing the name with pre or post respectively.

[package.metadata.commands]
pretest = "./setup.sh"
test = "cargo test"
posttest = "./teardown.sh"
$ cargo cmd test

[pretest]
> ./setup.sh
Setting up DB...

[test]
> cargo test
...

[posttest]
> ./teardown.sh
Tearing down DB...

License

MIT © Dan Reeves