/
config.rs
51 lines (49 loc) · 1.75 KB
/
config.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::command_prelude::*;
use cargo::ops::cargo_config;
pub fn cli() -> App {
subcommand("config")
.about("Inspect configuration values")
.after_help("Run `cargo help config` for more detailed information.\n")
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommand(
subcommand("get")
.arg(Arg::new("key").help("The config key to display"))
.arg(
opt("format", "Display format")
.possible_values(cargo_config::ConfigFormat::POSSIBLE_VALUES)
.default_value("toml"),
)
.arg(opt(
"show-origin",
"Display where the config value is defined",
))
.arg(
opt("merged", "Whether or not to merge config values")
.possible_values(&["yes", "no"])
.default_value("yes"),
),
)
}
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
config
.cli_unstable()
.fail_if_stable_command(config, "config", 9301)?;
match args.subcommand() {
Some(("get", args)) => {
let opts = cargo_config::GetOptions {
key: args.value_of("key"),
format: args.value_of("format").unwrap().parse()?,
show_origin: args.is_present("show-origin"),
merged: args.value_of("merged") == Some("yes"),
};
cargo_config::get(config, &opts)?;
}
Some((cmd, _)) => {
unreachable!("unexpected command {}", cmd)
}
None => {
unreachable!("unexpected command")
}
}
Ok(())
}