-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
mod xtask; | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
env_logger::init_from_env("CARGO_LOG"); | ||
let cli = xtask::cli(); | ||
let matches = cli.get_matches(); | ||
|
||
let mut config = cargo::util::config::Config::default().unwrap_or_else(|e| { | ||
let mut eval = cargo::core::shell::Shell::new(); | ||
cargo::exit_with_error(e.into(), &mut eval) | ||
}); | ||
if let Err(e) = xtask::exec(&matches, &mut config) { | ||
cargo::exit_with_error(e, &mut config.shell()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use cargo::util::command_prelude::*; | ||
|
||
pub fn cli() -> clap::Command { | ||
clap::Command::new("xtask") | ||
.arg( | ||
opt( | ||
"verbose", | ||
"Use verbose output (-vv very verbose/build.rs output)", | ||
) | ||
.short('v') | ||
.action(ArgAction::Count) | ||
.global(true), | ||
) | ||
.arg_quiet() | ||
.arg( | ||
opt("color", "Coloring: auto, always, never") | ||
.value_name("WHEN") | ||
.global(true), | ||
) | ||
.arg(flag("frozen", "Require Cargo.lock and cache are up to date").global(true)) | ||
.arg(flag("locked", "Require Cargo.lock is up to date").global(true)) | ||
.arg(flag("offline", "Run without accessing the network").global(true)) | ||
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true)) | ||
.arg( | ||
Arg::new("unstable-features") | ||
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details") | ||
.short('Z') | ||
.value_name("FLAG") | ||
.action(ArgAction::Append) | ||
.global(true), | ||
) | ||
} | ||
|
||
pub fn exec(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> cargo::CliResult { | ||
config_configure(config, args)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn config_configure(config: &mut Config, args: &ArgMatches) -> CliResult { | ||
let verbose = args.verbose(); | ||
// quiet is unusual because it is redefined in some subcommands in order | ||
// to provide custom help text. | ||
let quiet = args.flag("quiet"); | ||
let color = args.get_one::<String>("color").map(String::as_str); | ||
let frozen = args.flag("frozen"); | ||
let locked = args.flag("locked"); | ||
let offline = args.flag("offline"); | ||
let mut unstable_flags = vec![]; | ||
if let Some(values) = args.get_many::<String>("unstable-features") { | ||
unstable_flags.extend(values.cloned()); | ||
} | ||
let mut config_args = vec![]; | ||
if let Some(values) = args.get_many::<String>("config") { | ||
config_args.extend(values.cloned()); | ||
} | ||
config.configure( | ||
verbose, | ||
quiet, | ||
color, | ||
frozen, | ||
locked, | ||
offline, | ||
&None, | ||
&unstable_flags, | ||
&config_args, | ||
)?; | ||
Ok(()) | ||
} |