From: Alex Crichton Date: Fri, 19 Feb 2016 07:26:25 +0000 (-0800) Subject: Add configuration keys for -v, --color X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~15^2~3^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=be48d5b139d238bc3841b9d352d3ee98dd2089df;p=cargo.git Add configuration keys for -v, --color This commit adds configuration keys for: [term] verbose = true color = 'auto' These are all meant to be proxies for the command line flags but configured on a global basis if desired. --- diff --git a/src/bin/bench.rs b/src/bin/bench.rs index 96203de1a..2dd2399ed 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -11,8 +11,8 @@ pub struct Options { flag_no_default_features: bool, flag_target: Option, flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_lib: bool, flag_bin: Vec, @@ -63,8 +63,9 @@ Compilation can be customized with the `bench` profile in the manifest. pub fn execute(options: Options, config: &Config) -> CliResult> { let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let ops = ops::TestOptions { no_run: options.flag_no_run, diff --git a/src/bin/build.rs b/src/bin/build.rs index be550f475..5a66ca754 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -13,8 +13,8 @@ pub struct Options { flag_no_default_features: bool, flag_target: Option, flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_release: bool, flag_lib: bool, @@ -61,8 +61,9 @@ the --release flag will use the `release` profile instead. pub fn execute(options: Options, config: &Config) -> CliResult> { debug!("executing; cmd=cargo-build; args={:?}", env::args().collect::>()); - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 9011ca1fe..4ffa5ea8a 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -16,9 +16,9 @@ use cargo::util::{self, CliResult, lev_distance, Config, human, CargoResult, Cha #[derive(RustcDecodable)] pub struct Flags { flag_list: bool, - flag_verbose: bool, flag_version: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, arg_command: String, arg_args: Vec, @@ -108,8 +108,9 @@ mod subcommands { on this top-level information. */ fn execute(flags: Flags, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(flags.flag_verbose, flags.flag_quiet)); - try!(config.shell().set_color_config(flags.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(flags.flag_verbose, + flags.flag_quiet, + &flags.flag_color)); init_git_transports(config); cargo::util::job::setup(); diff --git a/src/bin/clean.rs b/src/bin/clean.rs index fa3ef0e50..5bcb10aeb 100644 --- a/src/bin/clean.rs +++ b/src/bin/clean.rs @@ -9,8 +9,8 @@ pub struct Options { flag_package: Vec, flag_target: Option, flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_release: bool, } @@ -38,9 +38,10 @@ and its format, see the `cargo help pkgid` command. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::>()); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let opts = ops::CleanOptions { diff --git a/src/bin/doc.rs b/src/bin/doc.rs index 4907575f2..3cb732738 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -11,9 +11,9 @@ pub struct Options { flag_no_default_features: bool, flag_no_deps: bool, flag_open: bool, - flag_verbose: bool, flag_release: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_package: Vec, } @@ -49,8 +49,9 @@ the `cargo help pkgid` command. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); diff --git a/src/bin/fetch.rs b/src/bin/fetch.rs index cd17ef9b5..1f32e8741 100644 --- a/src/bin/fetch.rs +++ b/src/bin/fetch.rs @@ -5,8 +5,8 @@ use cargo::util::important_paths::find_root_manifest_for_wd; #[derive(RustcDecodable)] pub struct Options { flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, } @@ -34,8 +34,9 @@ all updated. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); try!(ops::fetch(&root, config)); Ok(None) diff --git a/src/bin/generate_lockfile.rs b/src/bin/generate_lockfile.rs index 197a2319a..7e50eff26 100644 --- a/src/bin/generate_lockfile.rs +++ b/src/bin/generate_lockfile.rs @@ -7,8 +7,8 @@ use cargo::util::important_paths::find_root_manifest_for_wd; #[derive(RustcDecodable)] pub struct Options { flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, } @@ -28,8 +28,9 @@ Options: pub fn execute(options: Options, config: &Config) -> CliResult> { debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::>()); - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); try!(ops::generate_lockfile(&root, config)); diff --git a/src/bin/git_checkout.rs b/src/bin/git_checkout.rs index 1aa13bc6e..a45305514 100644 --- a/src/bin/git_checkout.rs +++ b/src/bin/git_checkout.rs @@ -6,8 +6,8 @@ use cargo::util::{Config, CliResult, CliError, human, ToUrl}; pub struct Options { flag_url: String, flag_reference: String, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, } @@ -26,8 +26,9 @@ Options: "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let Options { flag_url: url, flag_reference: reference, .. } = options; let url = try!(url.to_url().map_err(|e| { diff --git a/src/bin/init.rs b/src/bin/init.rs index cfc2b11d4..8856f8b35 100644 --- a/src/bin/init.rs +++ b/src/bin/init.rs @@ -5,8 +5,8 @@ use cargo::util::{CliResult, Config}; #[derive(RustcDecodable)] pub struct Options { - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_bin: bool, arg_path: Option, @@ -35,8 +35,9 @@ Options: pub fn execute(options: Options, config: &Config) -> CliResult> { debug!("executing; cmd=cargo-init; args={:?}", env::args().collect::>()); - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let Options { flag_bin, arg_path, flag_name, flag_vcs, .. } = options; diff --git a/src/bin/install.rs b/src/bin/install.rs index ece80f44c..bd2c3191b 100644 --- a/src/bin/install.rs +++ b/src/bin/install.rs @@ -10,8 +10,8 @@ pub struct Options { flag_debug: bool, flag_bin: Vec, flag_example: Vec, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_root: Option, flag_list: bool, @@ -83,8 +83,9 @@ The `--list` option will list all installed packages (and their versions). "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let compile_opts = ops::CompileOptions { config: config, diff --git a/src/bin/login.rs b/src/bin/login.rs index 70ef64d8e..bfb8418e4 100644 --- a/src/bin/login.rs +++ b/src/bin/login.rs @@ -10,8 +10,8 @@ use cargo::util::{CliResult, Config, human, ChainError}; pub struct Options { flag_host: Option, arg_token: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, } @@ -31,8 +31,9 @@ Options: "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let token = match options.arg_token.clone() { Some(token) => token, None => { diff --git a/src/bin/metadata.rs b/src/bin/metadata.rs index 9093a1a78..c8375d95c 100644 --- a/src/bin/metadata.rs +++ b/src/bin/metadata.rs @@ -15,8 +15,8 @@ pub struct Options { flag_manifest_path: Option, flag_no_default_features: bool, flag_no_deps: bool, - flag_quiet: bool, - flag_verbose: bool, + flag_quiet: Option, + flag_verbose: Option, } pub const USAGE: &'static str = " @@ -41,8 +41,9 @@ Options: "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let manifest = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let options = OutputMetadataOptions { diff --git a/src/bin/new.rs b/src/bin/new.rs index ba3921322..340fab90b 100644 --- a/src/bin/new.rs +++ b/src/bin/new.rs @@ -5,8 +5,8 @@ use cargo::util::{CliResult, Config}; #[derive(RustcDecodable)] pub struct Options { - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_bin: bool, arg_path: String, @@ -35,8 +35,9 @@ Options: pub fn execute(options: Options, config: &Config) -> CliResult> { debug!("executing; cmd=cargo-new; args={:?}", env::args().collect::>()); - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let Options { flag_bin, arg_path, flag_name, flag_vcs, .. } = options; diff --git a/src/bin/owner.rs b/src/bin/owner.rs index 40d4e20b9..33f49e511 100644 --- a/src/bin/owner.rs +++ b/src/bin/owner.rs @@ -8,8 +8,8 @@ pub struct Options { flag_add: Option>, flag_remove: Option>, flag_index: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_list: bool, } @@ -41,8 +41,9 @@ and troubleshooting. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let opts = ops::OwnersOptions { krate: options.arg_crate, token: options.flag_token, diff --git a/src/bin/package.rs b/src/bin/package.rs index c9bb161ef..37dd9a122 100644 --- a/src/bin/package.rs +++ b/src/bin/package.rs @@ -4,8 +4,8 @@ use cargo::util::important_paths::find_root_manifest_for_wd; #[derive(RustcDecodable)] pub struct Options { - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_manifest_path: Option, flag_no_verify: bool, @@ -32,8 +32,9 @@ Options: "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); try!(ops::package(&root, config, !options.flag_no_verify, diff --git a/src/bin/pkgid.rs b/src/bin/pkgid.rs index 7a88b2905..68e53236f 100644 --- a/src/bin/pkgid.rs +++ b/src/bin/pkgid.rs @@ -4,8 +4,8 @@ use cargo::util::important_paths::{find_root_manifest_for_wd}; #[derive(RustcDecodable)] pub struct Options { - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_manifest_path: Option, arg_spec: Option, @@ -47,8 +47,9 @@ Example Package IDs pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path.clone(), config.cwd())); let spec = options.arg_spec.as_ref().map(|s| &s[..]); diff --git a/src/bin/publish.rs b/src/bin/publish.rs index cf8f8f904..dac40fae3 100644 --- a/src/bin/publish.rs +++ b/src/bin/publish.rs @@ -7,8 +7,8 @@ pub struct Options { flag_host: Option, flag_token: Option, flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_no_verify: bool, } @@ -32,8 +32,9 @@ Options: "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let Options { flag_token: token, flag_host: host, diff --git a/src/bin/run.rs b/src/bin/run.rs index 1926bbf21..34f83c669 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -11,8 +11,8 @@ pub struct Options { flag_no_default_features: bool, flag_target: Option, flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_release: bool, arg_args: Vec, @@ -49,8 +49,9 @@ the ones before go to Cargo. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index 3337ffcff..fc4b89790 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -14,8 +14,8 @@ pub struct Options { flag_no_default_features: bool, flag_target: Option, flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_release: bool, flag_lib: bool, @@ -66,8 +66,9 @@ must be used to select which target is compiled. pub fn execute(options: Options, config: &Config) -> CliResult> { debug!("executing; cmd=cargo-rustc; args={:?}", env::args().collect::>()); - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); diff --git a/src/bin/rustdoc.rs b/src/bin/rustdoc.rs index 9949c24c1..ed53d769b 100644 --- a/src/bin/rustdoc.rs +++ b/src/bin/rustdoc.rs @@ -11,9 +11,9 @@ pub struct Options { flag_manifest_path: Option, flag_no_default_features: bool, flag_open: bool, - flag_verbose: bool, + flag_verbose: Option, flag_release: bool, - flag_quiet: bool, + flag_quiet: Option, flag_color: Option, flag_package: Option, flag_lib: bool, @@ -62,8 +62,9 @@ the `cargo help pkgid` command. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); diff --git a/src/bin/search.rs b/src/bin/search.rs index e40d193c2..fa8d792c2 100644 --- a/src/bin/search.rs +++ b/src/bin/search.rs @@ -4,8 +4,8 @@ use cargo::util::{CliResult, Config}; #[derive(RustcDecodable)] pub struct Options { flag_host: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, arg_query: String } @@ -26,8 +26,9 @@ Options: "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let Options { flag_host: host, arg_query: query, diff --git a/src/bin/test.rs b/src/bin/test.rs index 08b13df76..c92a3c6c5 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -17,8 +17,8 @@ pub struct Options { flag_example: Vec, flag_test: Vec, flag_bench: Vec, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_release: bool, flag_no_fail_fast: bool, @@ -74,9 +74,10 @@ by passing `--nocapture` to the test binaries: "; pub fn execute(options: Options, config: &Config) -> CliResult> { + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); let ops = ops::TestOptions { no_run: options.flag_no_run, diff --git a/src/bin/uninstall.rs b/src/bin/uninstall.rs index 5b4b345dd..ace6a2500 100644 --- a/src/bin/uninstall.rs +++ b/src/bin/uninstall.rs @@ -5,8 +5,8 @@ use cargo::util::{CliResult, Config}; pub struct Options { flag_bin: Vec, flag_root: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, arg_spec: String, @@ -34,8 +34,9 @@ only uninstall particular binaries. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = options.flag_root.as_ref().map(|s| &s[..]); try!(ops::uninstall(root, &options.arg_spec, &options.flag_bin, config)); diff --git a/src/bin/update.rs b/src/bin/update.rs index 1a718125a..77e4c470c 100644 --- a/src/bin/update.rs +++ b/src/bin/update.rs @@ -10,8 +10,8 @@ pub struct Options { flag_aggressive: bool, flag_precise: Option, flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, } @@ -54,8 +54,9 @@ For more information about package id specifications, see `cargo help pkgid`. pub fn execute(options: Options, config: &Config) -> CliResult> { debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::>()); - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let update_opts = ops::UpdateOptions { diff --git a/src/bin/verify_project.rs b/src/bin/verify_project.rs index 721b6eb7d..7079a4a6e 100644 --- a/src/bin/verify_project.rs +++ b/src/bin/verify_project.rs @@ -13,8 +13,8 @@ pub type Error = HashMap; #[derive(RustcDecodable)] pub struct Flags { flag_manifest_path: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, } @@ -34,8 +34,9 @@ Options: "; pub fn execute(args: Flags, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(args.flag_verbose, args.flag_quiet)); - try!(config.shell().set_color_config(args.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(args.flag_verbose, + args.flag_quiet, + &args.flag_color)); let mut contents = String::new(); let filename = args.flag_manifest_path.unwrap_or("Cargo.toml".into()); diff --git a/src/bin/yank.rs b/src/bin/yank.rs index feb2c73cc..60718c764 100644 --- a/src/bin/yank.rs +++ b/src/bin/yank.rs @@ -7,8 +7,8 @@ pub struct Options { flag_token: Option, flag_vers: Option, flag_index: Option, - flag_verbose: bool, - flag_quiet: bool, + flag_verbose: Option, + flag_quiet: Option, flag_color: Option, flag_undo: bool, } @@ -39,8 +39,9 @@ crates to be locked to any yanked version. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); - try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); + try!(config.configure_shell(options.flag_verbose, + options.flag_quiet, + &options.flag_color)); try!(ops::yank(config, options.arg_crate, options.flag_vers, diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 00df39b70..4df18656d 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -184,6 +184,22 @@ impl Config { } } + pub fn get_bool(&self, key: &str) -> CargoResult>> { + if let Some(v) = try!(self.get_env(key)) { + return Ok(Some(v)) + } + match try!(self.get(key)) { + Some(CV::Boolean(b, path)) => { + Ok(Some(Value { + val: b, + definition: Definition::Path(path), + })) + } + Some(val) => self.expected("bool", key, val), + None => Ok(None), + } + } + pub fn get_path(&self, key: &str) -> CargoResult>> { if let Some(val) = try!(self.get_string(&key)) { let is_path = val.val.contains("/") || @@ -253,6 +269,22 @@ impl Config { }) } + pub fn configure_shell(&self, + verbose: Option, + quiet: Option, + color: &Option) -> CargoResult<()> { + let cfg_verbose = try!(self.get_bool("term.verbose")).map(|v| v.val); + let cfg_color = try!(self.get_string("term.color")).map(|v| v.val); + let verbose = verbose.or(cfg_verbose).unwrap_or(false); + let quiet = quiet.unwrap_or(false); + let color = color.as_ref().or(cfg_color.as_ref()); + + try!(self.shell().set_verbosity(verbose, quiet)); + try!(self.shell().set_color_config(color.map(|s| &s[..]))); + + Ok(()) + } + fn load_values(&self) -> CargoResult<()> { let mut cfg = CV::Table(HashMap::new(), PathBuf::from(".")); diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index d69d6b300..bb213b25e 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -311,6 +311,7 @@ from_error! { ffi::NulError, term::Error, num::ParseIntError, + str::ParseBoolError, } impl From for Box { @@ -338,6 +339,7 @@ impl CargoError for url::ParseError {} impl CargoError for ffi::NulError {} impl CargoError for term::Error {} impl CargoError for num::ParseIntError {} +impl CargoError for str::ParseBoolError {} // ============================================================================= // Construction helpers diff --git a/src/doc/config.md b/src/doc/config.md index 3d66f8aeb..8b8bb5090 100644 --- a/src/doc/config.md +++ b/src/doc/config.md @@ -84,6 +84,10 @@ rustc = "rustc" # the rust compiler tool rustdoc = "rustdoc" # the doc generator tool target = "triple" # build for the target triple target-dir = "target" # path of where to place all generated artifacts + +[term] +verbose = false # whether cargo provides verbose output +color = 'auto' # whether cargo colorizes output ``` # Environment Variables