mirror of
https://github.com/casey/just.git
synced 2024-11-23 20:15:05 +03:00
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) highlight: bool,
|
||||||
pub(crate) invocation_directory: PathBuf,
|
pub(crate) invocation_directory: PathBuf,
|
||||||
pub(crate) load_dotenv: bool,
|
pub(crate) load_dotenv: bool,
|
||||||
pub(crate) quiet: bool,
|
|
||||||
pub(crate) search_config: SearchConfig,
|
pub(crate) search_config: SearchConfig,
|
||||||
pub(crate) shell: String,
|
pub(crate) shell: String,
|
||||||
pub(crate) shell_args: Vec<String>,
|
pub(crate) shell_args: Vec<String>,
|
||||||
@ -297,7 +296,11 @@ impl Config {
|
|||||||
pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult<Self> {
|
pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult<Self> {
|
||||||
let invocation_directory = env::current_dir().context(config_error::CurrentDir)?;
|
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(
|
let color = Self::color_from_value(
|
||||||
matches
|
matches
|
||||||
@ -433,7 +436,6 @@ impl Config {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
dry_run: matches.is_present(arg::DRY_RUN),
|
dry_run: matches.is_present(arg::DRY_RUN),
|
||||||
highlight: !matches.is_present(arg::NO_HIGHLIGHT),
|
highlight: !matches.is_present(arg::NO_HIGHLIGHT),
|
||||||
quiet: matches.is_present(arg::QUIET),
|
|
||||||
shell: matches.value_of(arg::SHELL).unwrap().to_owned(),
|
shell: matches.value_of(arg::SHELL).unwrap().to_owned(),
|
||||||
load_dotenv: !matches.is_present(arg::NO_DOTENV),
|
load_dotenv: !matches.is_present(arg::NO_DOTENV),
|
||||||
unsorted: matches.is_present(arg::UNSORTED),
|
unsorted: matches.is_present(arg::UNSORTED),
|
||||||
@ -739,7 +741,7 @@ impl Config {
|
|||||||
|
|
||||||
let result = justfile.run(&self, search, overrides, arguments);
|
let result = justfile.run(&self, search, overrides, arguments);
|
||||||
|
|
||||||
if !self.quiet {
|
if !self.verbosity.quiet() {
|
||||||
result.eprint(self.color)
|
result.eprint(self.color)
|
||||||
} else {
|
} else {
|
||||||
result.map_err(|err| err.code())
|
result.map_err(|err| err.code())
|
||||||
@ -868,7 +870,6 @@ ARGS:
|
|||||||
$(color: $color:expr,)?
|
$(color: $color:expr,)?
|
||||||
$(dry_run: $dry_run:expr,)?
|
$(dry_run: $dry_run:expr,)?
|
||||||
$(highlight: $highlight:expr,)?
|
$(highlight: $highlight:expr,)?
|
||||||
$(quiet: $quiet:expr,)?
|
|
||||||
$(search_config: $search_config:expr,)?
|
$(search_config: $search_config:expr,)?
|
||||||
$(shell: $shell:expr,)?
|
$(shell: $shell:expr,)?
|
||||||
$(shell_args: $shell_args:expr,)?
|
$(shell_args: $shell_args:expr,)?
|
||||||
@ -888,7 +889,6 @@ ARGS:
|
|||||||
$(color: $color,)?
|
$(color: $color,)?
|
||||||
$(dry_run: $dry_run,)?
|
$(dry_run: $dry_run,)?
|
||||||
$(highlight: $highlight,)?
|
$(highlight: $highlight,)?
|
||||||
$(quiet: $quiet,)?
|
|
||||||
$(search_config: $search_config,)?
|
$(search_config: $search_config,)?
|
||||||
$(shell: $shell.to_string(),)?
|
$(shell: $shell.to_string(),)?
|
||||||
$(shell_args: $shell_args,)?
|
$(shell_args: $shell_args,)?
|
||||||
@ -1080,19 +1080,19 @@ ARGS:
|
|||||||
test! {
|
test! {
|
||||||
name: quiet_default,
|
name: quiet_default,
|
||||||
args: [],
|
args: [],
|
||||||
quiet: false,
|
verbosity: Verbosity::Taciturn,
|
||||||
}
|
}
|
||||||
|
|
||||||
test! {
|
test! {
|
||||||
name: quiet_long,
|
name: quiet_long,
|
||||||
args: ["--quiet"],
|
args: ["--quiet"],
|
||||||
quiet: true,
|
verbosity: Verbosity::Quiet,
|
||||||
}
|
}
|
||||||
|
|
||||||
test! {
|
test! {
|
||||||
name: quiet_short,
|
name: quiet_short,
|
||||||
args: ["-q"],
|
args: ["-q"],
|
||||||
quiet: true,
|
verbosity: Verbosity::Quiet,
|
||||||
}
|
}
|
||||||
|
|
||||||
test! {
|
test! {
|
||||||
|
@ -131,7 +131,7 @@ impl<'src, 'run> Evaluator<'src, 'run> {
|
|||||||
|
|
||||||
cmd.stdin(process::Stdio::inherit());
|
cmd.stdin(process::Stdio::inherit());
|
||||||
|
|
||||||
cmd.stderr(if self.config.quiet {
|
cmd.stderr(if self.config.verbosity.quiet() {
|
||||||
process::Stdio::null()
|
process::Stdio::null()
|
||||||
} else {
|
} else {
|
||||||
process::Stdio::inherit()
|
process::Stdio::inherit()
|
||||||
|
@ -236,7 +236,7 @@ impl<'src, D> Recipe<'src, D> {
|
|||||||
|
|
||||||
if config.dry_run
|
if config.dry_run
|
||||||
|| config.verbosity.loquacious()
|
|| config.verbosity.loquacious()
|
||||||
|| !((quiet_command ^ self.quiet) || config.quiet)
|
|| !((quiet_command ^ self.quiet) || config.verbosity.quiet())
|
||||||
{
|
{
|
||||||
let color = if config.highlight {
|
let color = if config.highlight {
|
||||||
config.color.command()
|
config.color.command()
|
||||||
@ -256,7 +256,7 @@ impl<'src, D> Recipe<'src, D> {
|
|||||||
|
|
||||||
cmd.arg(command);
|
cmd.arg(command);
|
||||||
|
|
||||||
if config.quiet {
|
if config.verbosity.quiet() {
|
||||||
cmd.stderr(Stdio::null());
|
cmd.stderr(Stdio::null());
|
||||||
cmd.stdout(Stdio::null());
|
cmd.stdout(Stdio::null());
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use Verbosity::*;
|
|||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub(crate) enum Verbosity {
|
pub(crate) enum Verbosity {
|
||||||
|
Quiet,
|
||||||
Taciturn,
|
Taciturn,
|
||||||
Loquacious,
|
Loquacious,
|
||||||
Grandiloquent,
|
Grandiloquent,
|
||||||
@ -16,16 +17,23 @@ impl Verbosity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn quiet(self) -> bool {
|
||||||
|
match self {
|
||||||
|
Quiet => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn loquacious(self) -> bool {
|
pub(crate) fn loquacious(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Taciturn => false,
|
Quiet | Taciturn => false,
|
||||||
Loquacious | Grandiloquent => true,
|
Loquacious | Grandiloquent => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn grandiloquent(self) -> bool {
|
pub(crate) fn grandiloquent(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Taciturn | Loquacious => false,
|
Quiet | Taciturn | Loquacious => false,
|
||||||
Grandiloquent => true,
|
Grandiloquent => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user