|
1 | 1 | use anyhow::anyhow;
|
2 | 2 | use cargo::core::{features, CliUnstable};
|
3 | 3 | 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 | +}; |
5 | 8 | use itertools::Itertools;
|
6 | 9 | use std::collections::HashMap;
|
7 | 10 | use std::fmt::Write;
|
@@ -33,9 +36,17 @@ pub fn main(config: &mut Config) -> CliResult {
|
33 | 36 | let args = match cli().try_get_matches() {
|
34 | 37 | Ok(args) => args,
|
35 | 38 | Err(e) => {
|
36 |
| - if e.kind == clap::ErrorKind::UnrecognizedSubcommand { |
| 39 | + if e.kind() == clap::ErrorKind::UnrecognizedSubcommand { |
37 | 40 | // 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 | + _ => None, |
| 48 | + }) |
| 49 | + .expect("UnrecognizedSubcommand implies the presence of InvalidSubcommand"); |
39 | 50 | return super::execute_external_subcommand(config, &cmd, &[&cmd, "--help"])
|
40 | 51 | .map_err(|_| e.into());
|
41 | 52 | } else {
|
@@ -286,9 +297,7 @@ For more information, see issue #10049 <https://github.com/rust-lang/cargo/issue
|
286 | 297 | // Note that an alias to an external command will not receive
|
287 | 298 | // these arguments. That may be confusing, but such is life.
|
288 | 299 | let global_args = GlobalArgs::new(args);
|
289 |
| - let new_args = cli() |
290 |
| - .setting(AppSettings::NoBinaryName) |
291 |
| - .try_get_matches_from(alias)?; |
| 300 | + let new_args = cli().no_binary_name(true).try_get_matches_from(alias)?; |
292 | 301 |
|
293 | 302 | let new_cmd = new_args.subcommand_name().expect("subcommand is required");
|
294 | 303 | already_expanded.push(cmd.to_string());
|
@@ -406,14 +415,11 @@ fn cli() -> App {
|
406 | 415 | "cargo [OPTIONS] [SUBCOMMAND]"
|
407 | 416 | };
|
408 | 417 | App::new("cargo")
|
409 |
| - .setting( |
410 |
| - AppSettings::DeriveDisplayOrder |
411 |
| - | AppSettings::AllowExternalSubcommands |
412 |
| - | AppSettings::NoAutoVersion, |
413 |
| - ) |
| 418 | + .allow_external_subcommands(true) |
| 419 | + .setting(AppSettings::DeriveDisplayOrder | AppSettings::NoAutoVersion) |
414 | 420 | // Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
|
415 | 421 | // opening clap up to allow us to style our help template
|
416 |
| - .global_setting(AppSettings::DisableColoredHelp) |
| 422 | + .disable_colored_help(true) |
417 | 423 | .override_usage(usage)
|
418 | 424 | .help_template(
|
419 | 425 | "\
|
|
0 commit comments