Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unnest task cmd output #3691

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions e2e/tasks/test_task_unnest
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ assert "mise run --output prefix c" "\
[c] c
[b] b
[a] a"

assert "mise run --no-timings --output prefix c 2>&1" '[c] $ echo c && mise run b
[c] c
[b] $ echo b && mise run a
[b] b
[a] $ echo a
[a] a'
21 changes: 13 additions & 8 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ impl Run {
"MISE_TASK_LEVEL".into(),
(*env::MISE_TASK_LEVEL + 1).to_string(),
);
if !self.timings {
env.insert("MISE_TASK_TIMINGS".to_string(), "0".to_string());
}
if let Some(cwd) = &*dirs::CWD {
env.insert("MISE_ORIGINAL_CWD".into(), cwd.display().to_string());
}
Expand Down Expand Up @@ -408,8 +411,8 @@ impl Run {
.bright()
.to_string();
if !self.quiet(Some(task)) {
let msg = format!("{prefix} {}", config.redact(cmd));
prefix_eprintln!(prefix, "{}", trunc(&msg));
let msg = trunc(prefix, config.redact(cmd).trim());
prefix_eprintln!(prefix, "{msg}")
}

if script.starts_with("#!") {
Expand Down Expand Up @@ -507,11 +510,12 @@ impl Run {
}

if !self.quiet(Some(task)) {
let cmd = format!("{} {}", display_path(file), args.join(" "));
let cmd = format!("{} {}", display_path(file), args.join(" "))
.trim()
.to_string();
let cmd = style::ebold(format!("$ {cmd}")).bright().to_string();
let cmd = trunc(&format!("{prefix} {}", config.redact(cmd)));
// TODO: prefix_eprintln!("{cmd}");
eprintln!("{cmd}");
let cmd = trunc(prefix, config.redact(cmd).trim());
prefix_eprintln!(prefix, "{cmd}");
}

self.exec(file, &args, task, &env, prefix)
Expand Down Expand Up @@ -860,9 +864,10 @@ pub enum TaskOutput {
Silent,
}

fn trunc(msg: &str) -> String {
fn trunc(prefix: &str, msg: &str) -> String {
let prefix_len = console::measure_text_width(prefix);
let msg = msg.lines().next().unwrap_or_default();
console::truncate_str(msg, *env::TERM_WIDTH, "…").to_string()
console::truncate_str(msg, *env::TERM_WIDTH - prefix_len - 1, "…").to_string()
}

fn err_no_task(name: &str) -> Result<()> {
Expand Down
Loading