Skip to content

Commit

Permalink
feat: respect --quiet in mise run
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 28, 2024
1 parent 4f5c239 commit 84b36c9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docs/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Hides elapsed time after each task completes

Default to always hide with `MISE_TASK_TIMINGS=0`

### `-q --quiet`

Don't show extra output

Examples:

# Runs the "lint" tasks. This needs to either be defined in mise.toml
Expand Down
4 changes: 4 additions & 0 deletions docs/cli/tasks/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ Hides elapsed time after each task completes

Default to always hide with `MISE_TASK_TIMINGS=0`

### `-q --quiet`

Don't show extra output

Examples:

# Runs the "lint" tasks. This needs to either be defined in mise.toml
Expand Down
2 changes: 2 additions & 0 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ The name of the script will be the name of the tasks.
flag "--no-timings" help="Hides elapsed time after each task completes" {
long_help "Hides elapsed time after each task completes\n\nDefault to always hide with `MISE_TASK_TIMINGS=0`"
}
flag "-q --quiet" help="Don't show extra output"
mount run="mise tasks --usage"
}
cmd "self-update" help="Updates mise itself." {
Expand Down Expand Up @@ -1333,6 +1334,7 @@ The name of the script will be the name of the tasks.
flag "--no-timings" help="Hides elapsed time after each task completes" {
long_help "Hides elapsed time after each task completes\n\nDefault to always hide with `MISE_TASK_TIMINGS=0`"
}
flag "-q --quiet" help="Don't show extra output"
arg "[TASK]" help="Tasks to run\nCan specify multiple tasks by separating with `:::`\ne.g.: mise run task1 arg1 arg2 ::: task2 arg1 arg2" default="default"
arg "[ARGS]..." help="Arguments to pass to the tasks. Use \":::\" to separate tasks" var=true
mount run="mise tasks --usage"
Expand Down
3 changes: 2 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,11 @@ impl Cli {
no_timings: self.no_timings,
output: run::TaskOutput::Prefix,
prefix: self.prefix,
quiet: self.quiet,
raw: self.raw,
timings: self.timings,
tool: Default::default(),
tmpdir: Default::default(),
tool: Default::default(),
}));
} else if let Some(cmd) = external::COMMANDS.get(&task) {
external::execute(
Expand Down
30 changes: 23 additions & 7 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ pub struct Run {
#[clap(long, alias = "no-timing", verbatim_doc_comment)]
pub no_timings: bool,

/// Don't show extra output
#[clap(long, short, verbatim_doc_comment)]
pub quiet: bool,

#[clap(skip)]
pub is_linear: bool,

Expand Down Expand Up @@ -323,11 +327,15 @@ impl Run {
fn run_task(&self, env: &BTreeMap<String, String>, task: &Task) -> Result<()> {
let prefix = task.estyled_prefix();
if SETTINGS.task_skip.contains(&task.name) {
eprintln!("{prefix} skipping task");
if !self.quiet {
eprintln!("{prefix} skipping task");
}
return Ok(());
}
if !self.force && self.sources_are_fresh(task)? {
eprintln!("{prefix} sources up-to-date, skipping");
if !self.quiet {
eprintln!("{prefix} sources up-to-date, skipping");
}
return Ok(());
}

Expand Down Expand Up @@ -401,7 +409,9 @@ impl Run {
.bright()
.to_string(),
);
eprintln!("{prefix} {cmd}");
if !self.quiet {
eprintln!("{prefix} {cmd}");
}

if script.starts_with("#!") {
let dir = tempfile::tempdir()?;
Expand Down Expand Up @@ -527,7 +537,9 @@ impl Run {

let cmd = format!("{} {}", display_path(file), args.join(" "));
let cmd = trunc(&style::ebold(format!("$ {cmd}")).bright().to_string());
eprintln!("{prefix} {cmd}");
if !self.quiet {
eprintln!("{prefix} {cmd}");
}

self.exec(file, &args, task, &env, prefix)
}
Expand Down Expand Up @@ -557,7 +569,7 @@ impl Run {
cmd.with_pass_signals();
match self.output {
TaskOutput::Prefix => cmd = cmd.prefix(format!("{prefix} ")),
TaskOutput::Interleave => {
TaskOutput::Quiet | TaskOutput::Interleave => {
cmd = cmd
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
Expand Down Expand Up @@ -585,7 +597,9 @@ impl Run {
}

fn output(&self, task: &Task) -> Result<TaskOutput> {
if self.prefix {
if self.quiet {
Ok(TaskOutput::Quiet)
} else if self.prefix {
Ok(TaskOutput::Prefix)
} else if self.interleave {
Ok(TaskOutput::Interleave)
Expand Down Expand Up @@ -754,7 +768,8 @@ impl Run {
}

fn timings(&self) -> bool {
!self.no_timings
!self.quiet
&& !self.no_timings
&& SETTINGS
.task_timings
.unwrap_or(self.output == TaskOutput::Prefix)
Expand Down Expand Up @@ -876,6 +891,7 @@ pub enum TaskOutput {
#[default]
Prefix,
Interleave,
Quiet,
}

fn trunc(msg: &str) -> String {
Expand Down
16 changes: 16 additions & 0 deletions xtasks/fig/src/mise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,14 @@ const completionSpec: Fig.Spec = {
],
"description": "Hides elapsed time after each task completes",
"isRepeatable": false
},
{
"name": [
"-q",
"--quiet"
],
"description": "Don't show extra output",
"isRepeatable": false
}
],
"generateSpec": usageGenerateSpec(["mise tasks --usage"]),
Expand Down Expand Up @@ -2431,6 +2439,14 @@ const completionSpec: Fig.Spec = {
],
"description": "Hides elapsed time after each task completes",
"isRepeatable": false
},
{
"name": [
"-q",
"--quiet"
],
"description": "Don't show extra output",
"isRepeatable": false
}
],
"args": [
Expand Down

0 comments on commit 84b36c9

Please sign in to comment.