|
| 1 | +use cargo::util::command_prelude::*; |
| 2 | + |
| 3 | +pub fn cli() -> clap::Command { |
| 4 | + clap::Command::new("xtask") |
| 5 | + .arg( |
| 6 | + opt( |
| 7 | + "verbose", |
| 8 | + "Use verbose output (-vv very verbose/build.rs output)", |
| 9 | + ) |
| 10 | + .short('v') |
| 11 | + .action(ArgAction::Count) |
| 12 | + .global(true), |
| 13 | + ) |
| 14 | + .arg_quiet() |
| 15 | + .arg( |
| 16 | + opt("color", "Coloring: auto, always, never") |
| 17 | + .value_name("WHEN") |
| 18 | + .global(true), |
| 19 | + ) |
| 20 | + .arg(flag("frozen", "Require Cargo.lock and cache are up to date").global(true)) |
| 21 | + .arg(flag("locked", "Require Cargo.lock is up to date").global(true)) |
| 22 | + .arg(flag("offline", "Run without accessing the network").global(true)) |
| 23 | + .arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true)) |
| 24 | + .arg( |
| 25 | + Arg::new("unstable-features") |
| 26 | + .help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details") |
| 27 | + .short('Z') |
| 28 | + .value_name("FLAG") |
| 29 | + .action(ArgAction::Append) |
| 30 | + .global(true), |
| 31 | + ) |
| 32 | +} |
| 33 | + |
| 34 | +pub fn exec(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> cargo::CliResult { |
| 35 | + config_configure(config, args)?; |
| 36 | + |
| 37 | + Ok(()) |
| 38 | +} |
| 39 | + |
| 40 | +fn config_configure(config: &mut Config, args: &ArgMatches) -> CliResult { |
| 41 | + let verbose = args.verbose(); |
| 42 | + // quiet is unusual because it is redefined in some subcommands in order |
| 43 | + // to provide custom help text. |
| 44 | + let quiet = args.flag("quiet"); |
| 45 | + let color = args.get_one::<String>("color").map(String::as_str); |
| 46 | + let frozen = args.flag("frozen"); |
| 47 | + let locked = args.flag("locked"); |
| 48 | + let offline = args.flag("offline"); |
| 49 | + let mut unstable_flags = vec![]; |
| 50 | + if let Some(values) = args.get_many::<String>("unstable-features") { |
| 51 | + unstable_flags.extend(values.cloned()); |
| 52 | + } |
| 53 | + let mut config_args = vec![]; |
| 54 | + if let Some(values) = args.get_many::<String>("config") { |
| 55 | + config_args.extend(values.cloned()); |
| 56 | + } |
| 57 | + config.configure( |
| 58 | + verbose, |
| 59 | + quiet, |
| 60 | + color, |
| 61 | + frozen, |
| 62 | + locked, |
| 63 | + offline, |
| 64 | + &None, |
| 65 | + &unstable_flags, |
| 66 | + &config_args, |
| 67 | + )?; |
| 68 | + Ok(()) |
| 69 | +} |
0 commit comments