Skip to content

Commit 79e839c

Browse files
committed
fix(task): label deps output by provider
1 parent 8c92adb commit 79e839c

6 files changed

Lines changed: 90 additions & 39 deletions

File tree

e2e/cli/test_deps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ assert_contains "mise deps --list" "schema.graphql"
5353
# Test --only flag
5454
assert_contains "mise deps --dry-run --only codegen 2>&1" "codegen"
5555
assert_not_contains "mise deps --dry-run --only codegen 2>&1" "npm"
56+
assert_contains "mise deps --force --only codegen 2>&1" "[deps.codegen] codegen"
5657

5758
# Test --skip flag
5859
assert_not_contains "mise deps --dry-run --skip npm 2>&1" "npm install"

src/cli/deps/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl DepsAdd {
6565

6666
let pkg_refs: Vec<&str> = packages.iter().map(|s| s.as_str()).collect();
6767
let cmd = provider.add_command(&pkg_refs, self.dev)?;
68-
DepsEngine::execute_command(&cmd, &env, provider.timeout())?;
68+
DepsEngine::execute_command(&cmd, &env, provider.timeout(), None, None)?;
6969
}
7070

7171
Ok(())

src/cli/deps/remove.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl DepsRemove {
6161

6262
let pkg_refs: Vec<&str> = packages.iter().map(|s| s.as_str()).collect();
6363
let cmd = provider.remove_command(&pkg_refs)?;
64-
DepsEngine::execute_command(&cmd, &env, provider.timeout())?;
64+
DepsEngine::execute_command(&cmd, &env, provider.timeout(), None, None)?;
6565
}
6666

6767
Ok(())

src/deps/engine.rs

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use crate::config::config_file::ConfigFile;
1111
use crate::config::{Config, Settings};
1212
use crate::tera::{BASE_CONTEXT, get_tera};
1313
use crate::ui::multi_progress_report::MultiProgressReport;
14+
use crate::ui::progress_report::SingleReport;
15+
use crate::ui::style;
1416

1517
type StepOutput = (DepsStepResult, Vec<PathBuf>);
1618
type JobOutput = Result<(String, DepsStepResult, Vec<PathBuf>), (String, eyre::Report)>;
@@ -405,14 +407,21 @@ impl DepsEngine {
405407
.collect();
406408

407409
crate::parallel::parallel(to_run_with_context, |(job, mpr, toolset_env)| async move {
408-
let pr = mpr.add(&job.cmd.description);
409-
match Self::execute_command(&job.cmd, &toolset_env, job.timeout) {
410+
let (stdout_prefix, stderr_prefix) = Self::deps_prefixes(&job.id);
411+
let pr = mpr.add(&stderr_prefix);
412+
match Self::execute_command(
413+
&job.cmd,
414+
&toolset_env,
415+
job.timeout,
416+
Some((&stdout_prefix, &stderr_prefix)),
417+
Some(pr.as_ref()),
418+
) {
410419
Ok(()) => {
411-
pr.finish_with_message(format!("{} done", job.cmd.description));
420+
pr.finish_with_message("done".to_string());
412421
Ok((DepsStepResult::Ran(job.id), job.outputs))
413422
}
414423
Err(e) => {
415-
pr.finish_with_message(format!("{} failed: {}", job.cmd.description, e));
424+
pr.finish_with_message(format!("failed: {e}"));
416425
Err(e)
417426
}
418427
}
@@ -550,31 +559,32 @@ impl DepsEngine {
550559
let toolset_env = toolset_env.clone();
551560

552561
let handle = join_set.spawn(async move {
553-
let pr = mpr.add(&job.cmd.description);
554562
let id = job.id;
563+
let (stdout_prefix, stderr_prefix) = Self::deps_prefixes(&id);
564+
let pr = mpr.add(&stderr_prefix);
555565
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
556-
Self::execute_command(&job.cmd, &toolset_env, job.timeout)
566+
Self::execute_command(
567+
&job.cmd,
568+
&toolset_env,
569+
job.timeout,
570+
Some((&stdout_prefix, &stderr_prefix)),
571+
Some(pr.as_ref()),
572+
)
557573
}));
558574
drop(permit);
559575

560576
match result {
561577
Ok(Ok(())) => {
562-
pr.finish_with_message(format!("{} done", job.cmd.description));
578+
pr.finish_with_message("done".to_string());
563579
let step = DepsStepResult::Ran(id.clone());
564580
Ok((id, step, job.outputs))
565581
}
566582
Ok(Err(e)) => {
567-
pr.finish_with_message(format!(
568-
"{} failed: {}",
569-
job.cmd.description, e
570-
));
583+
pr.finish_with_message(format!("failed: {e}"));
571584
Err((id, e))
572585
}
573586
Err(_) => {
574-
pr.finish_with_message(format!(
575-
"{} panicked",
576-
job.cmd.description
577-
));
587+
pr.finish_with_message("panicked".to_string());
578588
Err((id, eyre::eyre!("task panicked")))
579589
}
580590
}
@@ -696,6 +706,8 @@ impl DepsEngine {
696706
cmd: &super::DepsCommand,
697707
toolset_env: &BTreeMap<String, String>,
698708
timeout: Option<std::time::Duration>,
709+
prefixes: Option<(&str, &str)>,
710+
progress: Option<&dyn SingleReport>,
699711
) -> Result<()> {
700712
let cwd = match cmd.cwd.clone() {
701713
Some(dir) => dir,
@@ -742,7 +754,41 @@ impl DepsEngine {
742754
runner = runner.raw(true);
743755
}
744756

757+
if let Some((stdout_prefix, stderr_prefix)) = prefixes
758+
&& !Settings::get().raw
759+
{
760+
let stdout_prefix = stdout_prefix.to_string();
761+
let stderr_prefix = stderr_prefix.to_string();
762+
runner = runner
763+
.with_on_stdout(move |line| {
764+
if let Some(progress) = progress {
765+
progress.set_message(line.clone());
766+
}
767+
if console::colors_enabled() {
768+
prefix_println!(stdout_prefix, "{line}\x1b[0m");
769+
} else {
770+
prefix_println!(stdout_prefix, "{line}");
771+
}
772+
})
773+
.with_on_stderr(move |line| {
774+
if console::colors_enabled_stderr() {
775+
prefix_eprintln!(stderr_prefix, "{line}\x1b[0m");
776+
} else {
777+
prefix_eprintln!(stderr_prefix, "{line}");
778+
}
779+
});
780+
}
781+
745782
runner.execute()?;
746783
Ok(())
747784
}
785+
786+
fn deps_prefixes(id: &str) -> (String, String) {
787+
let name = format!("deps.{id}");
788+
let prefix = format!("[{name}]");
789+
(
790+
style::prefix(&prefix, &name, false),
791+
style::prefix(prefix, name, true),
792+
)
793+
}
748794
}

src/task/mod.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::task::task_script_parser::TaskScriptParser;
77
use crate::tera::get_tera;
88
use crate::ui::tree::TreeItem;
99
use crate::{dirs, env, file};
10-
use console::{Color, measure_text_width, truncate_str};
10+
use console::{measure_text_width, truncate_str};
1111
use eyre::{Result, bail, eyre};
1212
use fuzzy_matcher::FuzzyMatcher;
1313
use fuzzy_matcher::skim::SkimMatcherV2;
@@ -1026,18 +1026,7 @@ impl Task {
10261026
}
10271027

10281028
pub fn estyled_prefix(&self) -> String {
1029-
static COLORS: Lazy<Vec<Color>> =
1030-
Lazy::new(|| vec![Color::Blue, Color::Magenta, Color::Cyan, Color::Green]);
1031-
let hash = self.display_name.chars().map(|c| c as usize).sum::<usize>();
1032-
let mut styled = style::estyle(self.prefix()).fg(COLORS[hash % COLORS.len()]);
1033-
match (hash / COLORS.len()) % 4 {
1034-
1 => styled = styled.bold(),
1035-
2 => styled = styled.dim(),
1036-
3 => styled = styled.bright(),
1037-
_ => {}
1038-
}
1039-
1040-
style::ereset() + &styled.to_string()
1029+
style::prefix(self.prefix(), &self.display_name, true)
10411030
}
10421031

10431032
pub async fn dir(&self, config: &Arc<Config>) -> Result<Option<PathBuf>> {

src/ui/style.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
use std::path::Path;
2+
use std::sync::LazyLock;
23

34
use crate::file::display_path;
4-
use console::{StyledObject, style};
5-
6-
pub fn ereset() -> String {
7-
if console::colors_enabled_stderr() {
8-
"\x1b[0m".to_string()
9-
} else {
10-
"".to_string()
11-
}
12-
}
5+
use console::{Color, StyledObject, style};
136

147
pub fn estyle<D>(val: D) -> StyledObject<D> {
158
style(val).for_stderr()
@@ -90,3 +83,25 @@ pub fn ndim<D>(val: D) -> StyledObject<D> {
9083
pub fn nbright<D>(val: D) -> StyledObject<D> {
9184
nstyle(val).bright()
9285
}
86+
87+
pub fn prefix(label: impl Into<String>, hash_key: impl AsRef<str>, stderr: bool) -> String {
88+
static COLORS: LazyLock<Vec<Color>> =
89+
LazyLock::new(|| vec![Color::Blue, Color::Magenta, Color::Cyan, Color::Green]);
90+
91+
let label = label.into();
92+
let hash = hash_key.as_ref().chars().map(|c| c as usize).sum::<usize>();
93+
let styled = style(label).fg(COLORS[hash % COLORS.len()]);
94+
let mut styled = if stderr {
95+
styled.for_stderr()
96+
} else {
97+
styled.for_stdout()
98+
};
99+
match (hash / COLORS.len()) % 4 {
100+
1 => styled = styled.bold(),
101+
2 => styled = styled.dim(),
102+
3 => styled = styled.bright(),
103+
_ => {}
104+
}
105+
106+
styled.to_string()
107+
}

0 commit comments

Comments
 (0)