From 991f42d4ac9fa9caf2270ab53c91d651c5633119 Mon Sep 17 00:00:00 2001 From: Matt Boulanger Date: Thu, 1 Oct 2020 20:00:15 -0700 Subject: [PATCH] Move separate quiet config value to verbosity (#686) Moves the separate quiet variable in the `Config` struct into the existing verbosity field; the `Verbosity` enum now has a `Quiet` variant. When running, the presence of the quiet flag will set the verbosity to `Quiet`, overriding any number of verbosity flags in the CLI args. --- src/config.rs | 18 +++++++++--------- src/evaluator.rs | 2 +- src/recipe.rs | 4 ++-- src/verbosity.rs | 12 ++++++++++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/config.rs b/src/config.rs index d3c6a45a..922b6c99 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,7 +20,6 @@ pub(crate) struct Config { pub(crate) highlight: bool, pub(crate) invocation_directory: PathBuf, pub(crate) load_dotenv: bool, - pub(crate) quiet: bool, pub(crate) search_config: SearchConfig, pub(crate) shell: String, pub(crate) shell_args: Vec, @@ -297,7 +296,11 @@ impl Config { pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult { let invocation_directory = env::current_dir().context(config_error::CurrentDir)?; - let verbosity = Verbosity::from_flag_occurrences(matches.occurrences_of(arg::VERBOSE)); + let verbosity = if matches.is_present(arg::QUIET) { + Verbosity::Quiet + } else { + Verbosity::from_flag_occurrences(matches.occurrences_of(arg::VERBOSE)) + }; let color = Self::color_from_value( matches @@ -433,7 +436,6 @@ impl Config { Ok(Self { dry_run: matches.is_present(arg::DRY_RUN), highlight: !matches.is_present(arg::NO_HIGHLIGHT), - quiet: matches.is_present(arg::QUIET), shell: matches.value_of(arg::SHELL).unwrap().to_owned(), load_dotenv: !matches.is_present(arg::NO_DOTENV), unsorted: matches.is_present(arg::UNSORTED), @@ -739,7 +741,7 @@ impl Config { let result = justfile.run(&self, search, overrides, arguments); - if !self.quiet { + if !self.verbosity.quiet() { result.eprint(self.color) } else { result.map_err(|err| err.code()) @@ -868,7 +870,6 @@ ARGS: $(color: $color:expr,)? $(dry_run: $dry_run:expr,)? $(highlight: $highlight:expr,)? - $(quiet: $quiet:expr,)? $(search_config: $search_config:expr,)? $(shell: $shell:expr,)? $(shell_args: $shell_args:expr,)? @@ -888,7 +889,6 @@ ARGS: $(color: $color,)? $(dry_run: $dry_run,)? $(highlight: $highlight,)? - $(quiet: $quiet,)? $(search_config: $search_config,)? $(shell: $shell.to_string(),)? $(shell_args: $shell_args,)? @@ -1080,19 +1080,19 @@ ARGS: test! { name: quiet_default, args: [], - quiet: false, + verbosity: Verbosity::Taciturn, } test! { name: quiet_long, args: ["--quiet"], - quiet: true, + verbosity: Verbosity::Quiet, } test! { name: quiet_short, args: ["-q"], - quiet: true, + verbosity: Verbosity::Quiet, } test! { diff --git a/src/evaluator.rs b/src/evaluator.rs index 9db8327e..0f773dc8 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -131,7 +131,7 @@ impl<'src, 'run> Evaluator<'src, 'run> { cmd.stdin(process::Stdio::inherit()); - cmd.stderr(if self.config.quiet { + cmd.stderr(if self.config.verbosity.quiet() { process::Stdio::null() } else { process::Stdio::inherit() diff --git a/src/recipe.rs b/src/recipe.rs index c33477b7..aa3548a2 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -236,7 +236,7 @@ impl<'src, D> Recipe<'src, D> { if config.dry_run || config.verbosity.loquacious() - || !((quiet_command ^ self.quiet) || config.quiet) + || !((quiet_command ^ self.quiet) || config.verbosity.quiet()) { let color = if config.highlight { config.color.command() @@ -256,7 +256,7 @@ impl<'src, D> Recipe<'src, D> { cmd.arg(command); - if config.quiet { + if config.verbosity.quiet() { cmd.stderr(Stdio::null()); cmd.stdout(Stdio::null()); } diff --git a/src/verbosity.rs b/src/verbosity.rs index 61aefeaa..c0c2d5be 100644 --- a/src/verbosity.rs +++ b/src/verbosity.rs @@ -2,6 +2,7 @@ use Verbosity::*; #[derive(Copy, Clone, Debug, PartialEq)] pub(crate) enum Verbosity { + Quiet, Taciturn, Loquacious, Grandiloquent, @@ -16,16 +17,23 @@ impl Verbosity { } } + pub(crate) fn quiet(self) -> bool { + match self { + Quiet => true, + _ => false, + } + } + pub(crate) fn loquacious(self) -> bool { match self { - Taciturn => false, + Quiet | Taciturn => false, Loquacious | Grandiloquent => true, } } pub(crate) fn grandiloquent(self) -> bool { match self { - Taciturn | Loquacious => false, + Quiet | Taciturn | Loquacious => false, Grandiloquent => true, } }