Skip to content

Commit

Permalink
refactor: Resolve clap deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 28, 2022
1 parent 96948f7 commit 69ba69f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/bin/cargo/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use cargo::ops::{self, TestOptions};

pub fn cli() -> Command {
subcommand("bench")
.trailing_var_arg(true)
.about("Execute all benchmarks of a local package")
.arg_quiet()
.arg(
Expand All @@ -14,7 +13,8 @@ pub fn cli() -> Command {
.arg(
Arg::new("args")
.help("Arguments for the bench binary")
.num_args(0..),
.num_args(0..)
.trailing_var_arg(true),

This comment has been minimized.

Copy link
@CAD97

CAD97 Oct 7, 2022

Contributor

FYI, I think this changed behavior. Specifically, cargo test -- filter runs documentation tests on beta, but skips them on nightly. IIUC, this is coming from this condition changing; now that the trailing arguments are captured into args here, that test sees them and sets the compile filter to all_test_targets(), whereas previously the trailing varargs weren't considered for that check.

This also changes the help text output to no longer mention the ability to use --:

〉cargo +beta test --help
cargo.exe-test
Execute all unit and integration tests and build examples of a local package

USAGE:
    cargo.exe test [OPTIONS] [TESTNAME] [-- <args>...]

ARGS:
    <TESTNAME>    If specified, only run tests containing this string in their names
    <args>...     Arguments for the test binary

〉cargo +nightly test --help
Execute all unit and integration tests and build examples of a local package

Usage: cargo.exe test [OPTIONS] [TESTNAME] [args]...

Arguments:
  [TESTNAME]  If specified, only run tests containing this string in their names
  [args]...   Arguments for the test binary

This comment has been minimized.

Copy link
@epage

epage Oct 7, 2022

Author Contributor

Could you please open an issue for this? Tracking discussion off of a comment in a PR isn't ideal.

This comment has been minimized.

Copy link
@epage

epage Oct 7, 2022

Author Contributor

I think #11190 fixes this

)
.arg_targets_all(
"Benchmark only this package's library",
Expand Down
4 changes: 2 additions & 2 deletions src/bin/cargo/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ pub fn cli() -> Command {
subcommand("run")
// subcommand aliases are handled in aliased_command()
// .alias("r")
.trailing_var_arg(true)
.about("Run a binary or example of the local package")
.arg_quiet()
.arg(
Arg::new("args")
.value_parser(value_parser!(std::ffi::OsString))
.num_args(0..),
.num_args(0..)
.trailing_var_arg(true),
)
.arg_targets_bin_example(
"Name of the bin target to run",
Expand Down
8 changes: 6 additions & 2 deletions src/bin/cargo/commands/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ const CRATE_TYPE_ARG_NAME: &str = "crate-type";

pub fn cli() -> Command {
subcommand("rustc")
.trailing_var_arg(true)
.about("Compile a package, and pass extra options to the compiler")
.arg_quiet()
.arg(Arg::new("args").num_args(0..).help("Rustc flags"))
.arg(
Arg::new("args")
.num_args(0..)
.help("Rustc flags")
.trailing_var_arg(true),
)
.arg_package("Package to build")
.arg_jobs()
.arg_targets_all(
Expand Down
3 changes: 1 addition & 2 deletions src/bin/cargo/commands/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use crate::command_prelude::*;

pub fn cli() -> Command {
subcommand("rustdoc")
.trailing_var_arg(true)
.about("Build a package's documentation, using specified custom flags.")
.arg_quiet()
.arg(Arg::new("args").num_args(0..))
.arg(Arg::new("args").num_args(0..).trailing_var_arg(true))
.arg(flag(
"open",
"Opens the docs in a browser after the operation",
Expand Down
4 changes: 2 additions & 2 deletions src/bin/cargo/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub fn cli() -> Command {
subcommand("test")
// Subcommand aliases are handled in `aliased_command()`.
// .alias("t")
.trailing_var_arg(true)
.about("Execute all unit and integration tests and build examples of a local package")
.arg(
Arg::new("TESTNAME")
Expand All @@ -15,7 +14,8 @@ pub fn cli() -> Command {
.arg(
Arg::new("args")
.help("Arguments for the test binary")
.num_args(0..),
.num_args(0..)
.trailing_var_arg(true),
)
.arg(
flag(
Expand Down

0 comments on commit 69ba69f

Please sign in to comment.