Skip to content

Commit f78ffb9

Browse files
author
Jon Gjengset
committed
Avoid new deprecation warnings from clap 3.1.0
1 parent ea2a21c commit f78ffb9

File tree

10 files changed

+31
-22
lines changed

10 files changed

+31
-22
lines changed

src/bin/cargo/cli.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use anyhow::anyhow;
22
use cargo::core::{features, CliUnstable};
33
use cargo::{self, drop_print, drop_println, CliResult, Config};
4-
use clap::{AppSettings, Arg, ArgMatches};
4+
use clap::{
5+
error::{ContextKind, ContextValue},
6+
AppSettings, Arg, ArgMatches,
7+
};
58
use itertools::Itertools;
69
use std::collections::HashMap;
710
use std::fmt::Write;
@@ -33,9 +36,18 @@ pub fn main(config: &mut Config) -> CliResult {
3336
let args = match cli().try_get_matches() {
3437
Ok(args) => args,
3538
Err(e) => {
36-
if e.kind == clap::ErrorKind::UnrecognizedSubcommand {
39+
if e.kind() == clap::ErrorKind::UnrecognizedSubcommand {
3740
// An unrecognized subcommand might be an external subcommand.
38-
let cmd = e.info[0].clone();
41+
let cmd = e
42+
.context()
43+
.find_map(|c| match c {
44+
(ContextKind::InvalidSubcommand, &ContextValue::String(ref cmd)) => {
45+
Some(cmd)
46+
}
47+
(ContextKind::InvalidSubcommand, _) => unreachable!(),
48+
_ => None,
49+
})
50+
.unwrap();
3951
return super::execute_external_subcommand(config, &cmd, &[&cmd, "--help"])
4052
.map_err(|_| e.into());
4153
} else {
@@ -286,9 +298,7 @@ For more information, see issue #10049 <https://github.com/rust-lang/cargo/issue
286298
// Note that an alias to an external command will not receive
287299
// these arguments. That may be confusing, but such is life.
288300
let global_args = GlobalArgs::new(args);
289-
let new_args = cli()
290-
.setting(AppSettings::NoBinaryName)
291-
.try_get_matches_from(alias)?;
301+
let new_args = cli().no_binary_name(true).try_get_matches_from(alias)?;
292302

293303
let new_cmd = new_args.subcommand_name().expect("subcommand is required");
294304
already_expanded.push(cmd.to_string());
@@ -406,14 +416,11 @@ fn cli() -> App {
406416
"cargo [OPTIONS] [SUBCOMMAND]"
407417
};
408418
App::new("cargo")
409-
.setting(
410-
AppSettings::DeriveDisplayOrder
411-
| AppSettings::AllowExternalSubcommands
412-
| AppSettings::NoAutoVersion,
413-
)
419+
.allow_external_subcommands(true)
420+
.setting(AppSettings::DeriveDisplayOrder | AppSettings::NoAutoVersion)
414421
// Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
415422
// opening clap up to allow us to style our help template
416-
.global_setting(AppSettings::DisableColoredHelp)
423+
.disable_colored_help(true)
417424
.override_usage(usage)
418425
.help_template(
419426
"\

src/bin/cargo/commands/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use cargo::ops::{self, TestOptions};
33

44
pub fn cli() -> App {
55
subcommand("bench")
6-
.setting(AppSettings::TrailingVarArg)
6+
.trailing_var_arg(true)
77
.about("Execute all benchmarks of a local package")
88
.arg_quiet()
99
.arg(

src/bin/cargo/commands/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn cli() -> App {
55
subcommand("config")
66
.about("Inspect configuration values")
77
.after_help("Run `cargo help config` for more detailed information.\n")
8-
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
8+
.subcommand_required(true)
99
.subcommand(
1010
subcommand("get")
1111
.arg(Arg::new("key").help("The config key to display"))

src/bin/cargo/commands/git_checkout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const REMOVED: &str = "The `git-checkout` subcommand has been removed.";
55
pub fn cli() -> App {
66
subcommand("git-checkout")
77
.about("This subcommand has been removed")
8-
.setting(AppSettings::Hidden)
8+
.hide(true)
99
.override_help(REMOVED)
1010
}
1111

src/bin/cargo/commands/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn cli() -> App {
66
subcommand("report")
77
.about("Generate and display various kinds of reports")
88
.after_help("Run `cargo help report` for more detailed information.\n")
9-
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
9+
.subcommand_required(true)
1010
.subcommand(
1111
subcommand("future-incompatibilities")
1212
.alias("future-incompat")

src/bin/cargo/commands/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn cli() -> App {
88
subcommand("run")
99
// subcommand aliases are handled in aliased_command()
1010
// .alias("r")
11-
.setting(AppSettings::TrailingVarArg)
11+
.trailing_var_arg(true)
1212
.about("Run a binary or example of the local package")
1313
.arg_quiet()
1414
.arg(

src/bin/cargo/commands/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const CRATE_TYPE_ARG_NAME: &str = "crate-type";
77

88
pub fn cli() -> App {
99
subcommand("rustc")
10-
.setting(AppSettings::TrailingVarArg)
10+
.trailing_var_arg(true)
1111
.about("Compile a package, and pass extra options to the compiler")
1212
.arg_quiet()
1313
.arg(Arg::new("args").multiple_values(true).help("Rustc flags"))

src/bin/cargo/commands/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::command_prelude::*;
44

55
pub fn cli() -> App {
66
subcommand("rustdoc")
7-
.setting(AppSettings::TrailingVarArg)
7+
.trailing_var_arg(true)
88
.about("Build a package's documentation, using specified custom flags.")
99
.arg_quiet()
1010
.arg(Arg::new("args").multiple_values(true))

src/bin/cargo/commands/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn cli() -> App {
66
subcommand("test")
77
// Subcommand aliases are handled in `aliased_command()`.
88
// .alias("t")
9-
.setting(AppSettings::TrailingVarArg)
9+
.trailing_var_arg(true)
1010
.about("Execute all unit and integration tests and build examples of a local package")
1111
.arg(
1212
Arg::new("TESTNAME")

src/cargo/util/command_prelude.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub use crate::core::compiler::CompileMode;
2222
pub use crate::{CliError, CliResult, Config};
2323
pub use clap::{AppSettings, Arg, ArgMatches};
2424

25-
pub type App = clap::App<'static>;
25+
pub type App = clap::Command<'static>;
2626

2727
pub trait AppExt: Sized {
2828
fn _arg(self, arg: Arg<'static>) -> Self;
@@ -281,7 +281,9 @@ pub fn multi_opt(name: &'static str, value_name: &'static str, help: &'static st
281281
}
282282

283283
pub fn subcommand(name: &'static str) -> App {
284-
App::new(name).setting(AppSettings::DeriveDisplayOrder | AppSettings::DontCollapseArgsInUsage)
284+
App::new(name)
285+
.dont_collapse_args_in_usage(true)
286+
.setting(AppSettings::DeriveDisplayOrder)
285287
}
286288

287289
/// Determines whether or not to gate `--profile` as unstable when resolving it.

0 commit comments

Comments
 (0)