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.
This commit is contained in:
parent
d3ec3e4ce8
commit
991f42d4ac
@ -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<String>,
|
||||
@ -297,7 +296,11 @@ impl Config {
|
||||
pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult<Self> {
|
||||
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! {
|
||||
|
@ -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()
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user