Skip to content

Commit

Permalink
Print recipe command timestamps with --timestamps (#2084)
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed May 29, 2024
1 parent db52d95 commit d14aae1
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 8 deletions.
158 changes: 158 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [".", "crates/*"]
ansi_term = "0.12.0"
blake3 = { version = "1.5.0", features = ["rayon", "mmap"] }
camino = "1.0.4"
chrono = "0.4.38"
clap = { version = "4.0.0", features = ["env", "wrap_help"] }
clap_complete = "4.0.0"
clap_mangen = "0.2.20"
Expand Down
4 changes: 3 additions & 1 deletion bin/generate-completions
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

set -euxo pipefail

cargo build

for script in completions/*; do
shell=${script##*.}
if [ $shell == nu ]; then
continue
fi
cargo run -- --completions $shell > $script
./target/debug/just --completions $shell > $script
done
2 changes: 1 addition & 1 deletion completions/just.bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ _just() {

case "${cmd}" in
just)
opts="-n -f -q -u -v -d -c -e -l -s -E -g -h -V --check --chooser --color --command-color --yes --dry-run --dump-format --highlight --list-heading --list-prefix --no-aliases --no-deps --no-dotenv --no-highlight --justfile --quiet --set --shell --shell-arg --shell-command --clear-shell-args --unsorted --unstable --verbose --working-directory --changelog --choose --command --completions --dump --edit --evaluate --fmt --init --list --groups --man --show --summary --variables --dotenv-filename --dotenv-path --global-justfile --help --version [ARGUMENTS]..."
opts="-n -f -q -u -v -d -c -e -l -s -E -g -h -V --check --chooser --color --command-color --yes --dry-run --dump-format --highlight --list-heading --list-prefix --no-aliases --no-deps --no-dotenv --no-highlight --justfile --quiet --set --shell --shell-arg --shell-command --clear-shell-args --unsorted --unstable --verbose --working-directory --changelog --choose --command --completions --dump --edit --evaluate --fmt --init --list --groups --man --show --summary --variables --dotenv-filename --dotenv-path --global-justfile --timestamps --help --version [ARGUMENTS]..."
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
1 change: 1 addition & 0 deletions completions/just.elvish
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ set edit:completion:arg-completer[just] = {|@words|
cand --variables 'List names of variables'
cand -g 'Use global justfile'
cand --global-justfile 'Use global justfile'
cand --timestamps 'Print recipe command timestamps'
cand -h 'Print help'
cand --help 'Print help'
cand -V 'Print version'
Expand Down
1 change: 1 addition & 0 deletions completions/just.fish
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ complete -c just -l man -d 'Print man page'
complete -c just -l summary -d 'List names of available recipes'
complete -c just -l variables -d 'List names of variables'
complete -c just -s g -l global-justfile -d 'Use global justfile'
complete -c just -l timestamps -d 'Print recipe command timestamps'
complete -c just -s h -l help -d 'Print help'
complete -c just -s V -l version -d 'Print version'
1 change: 1 addition & 0 deletions completions/just.powershell
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Register-ArgumentCompleter -Native -CommandName 'just' -ScriptBlock {
[CompletionResult]::new('--variables', 'variables', [CompletionResultType]::ParameterName, 'List names of variables')
[CompletionResult]::new('-g', 'g', [CompletionResultType]::ParameterName, 'Use global justfile')
[CompletionResult]::new('--global-justfile', 'global-justfile', [CompletionResultType]::ParameterName, 'Use global justfile')
[CompletionResult]::new('--timestamps', 'timestamps', [CompletionResultType]::ParameterName, 'Print recipe command timestamps')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
Expand Down
1 change: 1 addition & 0 deletions completions/just.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ _just() {
'--variables[List names of variables]' \
'(-f --justfile -d --working-directory)-g[Use global justfile]' \
'(-f --justfile -d --working-directory)--global-justfile[Use global justfile]' \
'--timestamps[Print recipe command timestamps]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
Expand Down
10 changes: 10 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub(crate) struct Config {
pub(crate) shell_args: Option<Vec<String>>,
pub(crate) shell_command: bool,
pub(crate) subcommand: Subcommand,
pub(crate) timestamps: bool,
pub(crate) unsorted: bool,
pub(crate) unstable: bool,
pub(crate) verbosity: Verbosity,
Expand Down Expand Up @@ -109,6 +110,7 @@ mod arg {
pub(crate) const SHELL: &str = "SHELL";
pub(crate) const SHELL_ARG: &str = "SHELL-ARG";
pub(crate) const SHELL_COMMAND: &str = "SHELL-COMMAND";
pub(crate) const TIMESTAMPS: &str = "TIMESTAMPS";
pub(crate) const UNSORTED: &str = "UNSORTED";
pub(crate) const UNSTABLE: &str = "UNSTABLE";
pub(crate) const VERBOSE: &str = "VERBOSE";
Expand Down Expand Up @@ -482,6 +484,13 @@ impl Config {
.conflicts_with(arg::WORKING_DIRECTORY)
.help("Use global justfile")
)
.arg(
Arg::new(arg::TIMESTAMPS)
.action(ArgAction::SetTrue)
.long("timestamps")
.env("JUST_TIMESTAMPS")
.help("Print recipe command timestamps")
)
}

fn color_from_matches(matches: &ArgMatches) -> ConfigResult<Color> {
Expand Down Expand Up @@ -723,6 +732,7 @@ impl Config {
shell_args,
shell_command: matches.get_flag(arg::SHELL_COMMAND),
subcommand,
timestamps: matches.get_flag(arg::TIMESTAMPS),
unsorted: matches.get_flag(arg::UNSORTED),
unstable,
verbosity,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub(crate) use {
},
{
camino::Utf8Path,
chrono::Utc,
derivative::Derivative,
edit_distance::edit_distance,
lexiclean::Lexiclean,
Expand Down
20 changes: 14 additions & 6 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,20 @@ impl<'src, D> Recipe<'src, D> {
|| (context.settings.quiet && !self.no_quiet())
|| config.verbosity.quiet())
{
let color = if config.highlight {
config.color.command(config.command_color)
} else {
config.color
};
eprintln!("{}", color.stderr().paint(command));
let color = config
.highlight
.then(|| config.color.command(config.command_color))
.unwrap_or(config.color)
.stderr();

if config.timestamps {
eprint!(
"[{}] ",
color.paint(&Utc::now().format("%H:%M:%S").to_string())
);
}

eprintln!("{}", color.paint(command));
}

if config.dry_run {
Expand Down
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ mod string;
mod subsequents;
mod summary;
mod tempdir;
mod timestamps;
mod undefined_variables;
mod unstable;
#[cfg(target_family = "windows")]
Expand Down
Loading

0 comments on commit d14aae1

Please sign in to comment.