Use --command-color when printing shebang recipe commands (#1911)

This commit is contained in:
N 2024-05-14 20:53:59 -04:00 committed by GitHub
parent ea141a6891
commit d18bdef799
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 1 deletions

View File

@ -216,6 +216,11 @@ _sh:
hello='Yo'
echo "$hello from a shell script!"
_nu:
#!/usr/bin/env nu
let hellos = ["Greetings", "Yo", "Howdy"]
$hellos | each {|el| print $"($el) from a nushell script!" }
_ruby:
#!/usr/bin/env ruby
puts "Hello from ruby!"

View File

@ -310,7 +310,14 @@ impl<'src, D> Recipe<'src, D> {
if config.verbosity.loud() && (config.dry_run || self.quiet) {
for line in &evaluated_lines {
eprintln!("{line}");
eprintln!(
"{}",
config
.color
.command(config.command_color)
.stderr()
.paint(line)
);
}
}

View File

@ -58,6 +58,37 @@ fn simple() {
.run();
}
#[test]
fn echo() {
Test::new()
.justfile(
"
@baz:
#!/bin/sh
echo fizz
",
)
.stdout("fizz\n")
.stderr("#!/bin/sh\necho fizz\n")
.run();
}
#[test]
fn echo_with_command_color() {
Test::new()
.justfile(
"
@baz:
#!/bin/sh
echo fizz
",
)
.args(["--color", "always", "--command-color", "purple"])
.stdout("fizz\n")
.stderr("\u{1b}[1;35m#!/bin/sh\u{1b}[0m\n\u{1b}[1;35mecho fizz\u{1b}[0m\n")
.run();
}
// This test exists to make sure that shebang recipes run correctly. Although
// this script is still executed by a shell its behavior depends on the value of
// a variable and continuing even though a command fails, whereas in plain