If a CLI option is passed, that trumps any command line configuration, otherwise
just do what we did previously.
Closes #2588
use std::fs;
use std::path::PathBuf;
+use cargo::core::shell::Verbosity;
use cargo::execute_main_without_stdin;
-use cargo::util::{self, CliResult, lev_distance, Config, human, CargoResult, ChainError};
+use cargo::util::ChainError;
+use cargo::util::{self, CliResult, lev_distance, Config, human, CargoResult};
#[derive(RustcDecodable)]
pub struct Flags {
// `cargo -h` so we can go through the normal process of printing the
// help message.
"" | "help" if flags.arg_args.is_empty() => {
- config.shell().set_verbose(true);
+ config.shell().set_verbosity(Verbosity::Verbose);
let args = &["cargo".to_string(), "-h".to_string()];
let r = cargo::call_main_without_stdin(execute, config, USAGE, args,
false);
macro_rules! cmd{
($name:ident) => (if args[1] == stringify!($name).replace("_", "-") {
- config.shell().set_verbose(true);
+ config.shell().set_verbosity(Verbosity::Verbose);
let r = cargo::call_main_without_stdin($name::execute, config,
$name::USAGE,
&args,
use term::{self, Terminal, TerminfoTerminal, color, Attr};
use self::AdequateTerminal::{NoColor, Colored};
-use self::Verbosity::{Verbose, Normal, Quiet};
+use self::Verbosity::{Verbose, Quiet};
use self::ColorConfig::{Auto, Always, Never};
use util::errors::CargoResult;
self.err().say_status("warning:", message, YELLOW, false)
}
- pub fn set_verbosity(&mut self, verbose: bool, quiet: bool) -> CargoResult<()> {
- self.verbosity = match (verbose, quiet) {
- (true, true) => bail!("cannot set both --verbose and --quiet"),
- (true, false) => Verbose,
- (false, true) => Quiet,
- (false, false) => Normal
- };
- Ok(())
- }
-
- /// shortcut for commands that don't have both --verbose and --quiet
- pub fn set_verbose(&mut self, verbose: bool) {
- if verbose {
- self.verbosity = Verbose;
- } else {
- self.verbosity = Normal;
- }
+ pub fn set_verbosity(&mut self, verbosity: Verbosity) {
+ self.verbosity = verbosity;
}
pub fn set_color_config(&mut self, color: Option<&str>) -> CargoResult<()> {
color: &Option<String>) -> 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));
+ let verbosity = match (verbose, cfg_verbose, quiet) {
+ (Some(true), _, None) |
+ (None, Some(true), None) => Verbosity::Verbose,
+
+ // command line takes precedence over configuration, so ignore the
+ // configuration.
+ (None, _, Some(true)) => Verbosity::Quiet,
+
+ // Can't pass both at the same time on the command line regardless
+ // of configuration.
+ (Some(true), _, Some(true)) => {
+ bail!("cannot set both --verbose and --quiet");
+ }
+
+ // Can't actually get `Some(false)` as a value from the command
+ // line, so just ignore them here to appease exhaustiveness checking
+ // in match statements.
+ (Some(false), _, _) |
+ (_, _, Some(false)) |
+
+ (None, Some(false), None) |
+ (None, None, None) => Verbosity::Normal,
+ };
+
+ self.shell().set_verbosity(verbosity);
try!(self.shell().set_color_config(color.map(|s| &s[..])));
Ok(())
error = ERROR)));
});
+test!(quiet_and_verbose_config {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [project]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file(".cargo/config", r#"
+ [term]
+ verbose = true
+ "#)
+ .file("src/main.rs", r#"
+ fn main() { println!("hello"); }
+ "#);
+
+ assert_that(p.cargo_process("run").arg("-q"),
+ execs().with_status(0));
+});
+
test!(simple_with_args {
let p = project("foo")
.file("Cargo.toml", r#"