Description
Describe the problem you are trying to solve
Some project have a list of example, usually in the example
folder. It would be nice if it was possible to:
- list them all (so you can run them later with
cargo run --example $name_of_the_example
) - run all of them in one command (it may be useful in CI).
- a bit like
cargo test
, this should count the number of panic/non 0 exit code - it should be possible to provide a list of arguments that would be passed to each the examples
- a bit like
Describe the solution you'd like
-
I think a new command
cargo list
that would output (in separate sections) the list of examples, the list of binaries, and the list of libraries provided by the current crate would be a nice addition. It should be possible to filter the output with flags like--example
,--binaries
or--libraries
. Maybe the list of features available could also be listed? -
I think a new subcommand of
cargo run
should be added:cargo run --examples
. Like cargo run, all arguments after--
should be passed to the examples binaries. It would be equivalent to do:
for example in examples/*.rs
do
cargo run --example "$(basename "$example")" -- $args
done
A flag --exclude $example
may be added to run all examples but $example
(and would only make sense if --examples
is used). Similarly, cargo run --binaries
could be added to run all binaries of a crate.
Notes
In some cases, like a 3d crate, or interactive example, it would not be wise to run all examples but I don't think it's an issue. The proposed cargo list
and cargo run --examples
would still be really useful for most cases.