Skip to content
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
2 changes: 2 additions & 0 deletions src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ pub struct Arguments {
value_name = "TEMPDIR"
)]
pub(crate) tempdir: Option<PathBuf>,
#[arg(env = "JUST_TIME", help = "Print recipe execution time", long)]
pub(crate) time: bool,
#[arg(env = "JUST_TIMESTAMP", help = "Print recipe command timestamps", long)]
pub(crate) timestamp: bool,
#[arg(
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub(crate) struct Config {
pub(crate) shell_command: bool,
pub(crate) subcommand: Subcommand,
pub(crate) tempdir: Option<PathBuf>,
pub(crate) time: bool,
pub(crate) timestamp: bool,
pub(crate) timestamp_format: String,
pub(crate) unsorted: bool,
Expand Down Expand Up @@ -281,6 +282,7 @@ impl Config {
shell_command: arguments.shell_command,
subcommand,
tempdir: arguments.tempdir,
time: arguments.time,
timestamp: arguments.timestamp,
timestamp_format: arguments.timestamp_format,
unsorted: arguments.unsorted,
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ pub(crate) use {
slice,
str::{self, Chars, FromStr},
sync::{Arc, LazyLock, Mutex, MutexGuard},
thread, vec,
thread,
time::Instant,
vec,
},
strum::{Display, EnumDiscriminants, EnumIter, EnumString, IntoStaticStr},
tempfile::TempDir,
Expand Down
24 changes: 23 additions & 1 deletion src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,33 @@ impl<'src> Recipe<'src> {

let evaluator = Evaluator::new(context, BTreeMap::new(), is_dependency, scope);

if self.is_script() {
let start = Instant::now();
let result = if self.is_script() {
self.run_script(context, scope, positional, evaluator)
} else {
self.run_linewise(context, scope, positional, evaluator)
};
let elapsed = start.elapsed();

if context.config.time {
let color = if context.config.highlight {
context.config.color.command(context.config.command_color)
} else {
context.config.color
}
.stderr();

let prefix = color.prefix();
let suffix = color.suffix();
let recipe_name = self.name.lexeme();

eprintln!(
"{prefix}---> {recipe_name} completed in {:.3}s{suffix}",
elapsed.as_secs_f64(),
);
}

result
}

fn run_linewise<'run>(
Expand Down
15 changes: 15 additions & 0 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,18 @@ fn one_flag_only_allows_one_invocation() {
.stderr("error: Expected 1 command-line recipe invocation but found 2.\n")
.failure();
}

#[test]
fn time_reports_time_when_specified() {
Test::new()
.justfile(
"
foo:
@echo FOO
",
)
.arg("--time")
.stdout("FOO\n")
.stderr_regex(r"---> foo completed in \d+\.\d+s\n")
.success();
}