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

Add --quiet, --timings, --colo[u]r, --bell #698

Merged
merged 2 commits into from
Nov 27, 2023
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
10 changes: 10 additions & 0 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion completions/bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 19,7 @@ _watchexec() {

case "${cmd}" in
watchexec)
opts="-w -c -o -W -r -s -k -d -p -n -E -1 -N -e -f -i -v -h -V --watch --clear --on-busy-update --watch-when-idle --restart --signal --kill --stop-signal --stop-timeout --debounce --stdin-quit --no-vcs-ignore --no-project-ignore --no-global-ignore --no-default-ignore --no-discover-ignore --ignore-nothing --postpone --delay-run --poll --shell --no-shell-long --no-environment --emit-events-to --only-emit-events --env --no-process-group --notify --project-origin --workdir --exts --filter --filter-file --ignore --ignore-file --fs-events --no-meta --print-events --verbose --log-file --manual --completions --help --version [COMMAND]..."
opts="-w -c -o -W -r -s -k -d -p -n -E -1 -N -q -e -f -i -v -h -V --watch --clear --on-busy-update --watch-when-idle --restart --signal --kill --stop-signal --stop-timeout --debounce --stdin-quit --no-vcs-ignore --no-project-ignore --no-global-ignore --no-default-ignore --no-discover-ignore --ignore-nothing --postpone --delay-run --poll --shell --no-shell-long --no-environment --emit-events-to --only-emit-events --env --no-process-group --notify --color --timings --quiet --bell --project-origin --workdir --exts --filter --filter-file --ignore --ignore-file --fs-events --no-meta --print-events --verbose --log-file --manual --completions --help --version [COMMAND]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -97,6 97,10 @@ _watchexec() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--color)
COMPREPLY=($(compgen -W "auto always never" -- "${cur}"))
return 0
;;
--project-origin)
COMPREPLY=($(compgen -f "${cur}"))
return 0
Expand Down
5 changes: 5 additions & 0 deletions completions/elvish
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 36,7 @@ set edit:completion:arg-completer[watchexec] = {|@words|
cand --emit-events-to 'Configure event emission'
cand -E 'Add env vars to the command'
cand --env 'Add env vars to the command'
cand --color 'When to use terminal colours'
cand --project-origin 'Set the project origin'
cand --workdir 'Set the working directory'
cand -e 'Filename extensions to filter to'
Expand Down Expand Up @@ -72,6 73,10 @@ set edit:completion:arg-completer[watchexec] = {|@words|
cand -1 'Testing only: exit Watchexec after the first run'
cand -N 'Alert when commands start and end'
cand --notify 'Alert when commands start and end'
cand --timings 'Print how long the command took to run'
cand -q 'Don''t print starting and stopping messages'
cand --quiet 'Don''t print starting and stopping messages'
cand --bell 'Ring the terminal bell on command completion'
cand --no-meta 'Don''t emit fs events for metadata changes'
cand --print-events 'Print events that trigger actions'
cand -v 'Set diagnostic log level'
Expand Down
4 changes: 4 additions & 0 deletions completions/fish
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 10,7 @@ complete -c watchexec -l poll -d 'Poll for filesystem changes' -r
complete -c watchexec -l shell -d 'Use a different shell' -r
complete -c watchexec -l emit-events-to -d 'Configure event emission' -r -f -a "{environment '',stdin '',file '',json-stdin '',json-file '',none ''}"
complete -c watchexec -s E -l env -d 'Add env vars to the command' -r
complete -c watchexec -l color -d 'When to use terminal colours' -r -f -a "{auto '',always '',never ''}"
complete -c watchexec -l project-origin -d 'Set the project origin' -r -f -a "(__fish_complete_directories)"
complete -c watchexec -l workdir -d 'Set the working directory' -r -f -a "(__fish_complete_directories)"
complete -c watchexec -s e -l exts -d 'Filename extensions to filter to' -r
Expand Down Expand Up @@ -38,6 39,9 @@ complete -c watchexec -l only-emit-events -d 'Only emit events to stdout, run no
complete -c watchexec -l no-process-group -d 'Don\'t use a process group'
complete -c watchexec -s 1 -d 'Testing only: exit Watchexec after the first run'
complete -c watchexec -s N -l notify -d 'Alert when commands start and end'
complete -c watchexec -l timings -d 'Print how long the command took to run'
complete -c watchexec -s q -l quiet -d 'Don\'t print starting and stopping messages'
complete -c watchexec -l bell -d 'Ring the terminal bell on command completion'
complete -c watchexec -l no-meta -d 'Don\'t emit fs events for metadata changes'
complete -c watchexec -l print-events -d 'Print events that trigger actions'
complete -c watchexec -s v -l verbose -d 'Set diagnostic log level'
Expand Down
8 changes: 8 additions & 0 deletions completions/nu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,10 @@ module completions {
[ "environment" "stdin" "file" "json-stdin" "json-file" "none" ]
}

def "nu-complete watchexec color" [] {
[ "auto" "always" "never" ]
}

def "nu-complete watchexec filter_fs_events" [] {
[ "access" "create" "remove" "rename" "modify" "metadata" ]
}
Expand Down Expand Up @@ -53,6 57,10 @@ module completions {
--no-process-group # Don't use a process group
-1 # Testing only: exit Watchexec after the first run
--notify(-N) # Alert when commands start and end
--color: string@"nu-complete watchexec color" # When to use terminal colours
--timings # Print how long the command took to run
--quiet(-q) # Don't print starting and stopping messages
--bell # Ring the terminal bell on command completion
--project-origin: string # Set the project origin
--workdir: string # Set the working directory
--exts(-e): string # Filename extensions to filter to
Expand Down
5 changes: 5 additions & 0 deletions completions/powershell
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 39,7 @@ Register-ArgumentCompleter -Native -CommandName 'watchexec' -ScriptBlock {
[CompletionResult]::new('--emit-events-to', 'emit-events-to', [CompletionResultType]::ParameterName, 'Configure event emission')
[CompletionResult]::new('-E', 'E ', [CompletionResultType]::ParameterName, 'Add env vars to the command')
[CompletionResult]::new('--env', 'env', [CompletionResultType]::ParameterName, 'Add env vars to the command')
[CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'When to use terminal colours')
[CompletionResult]::new('--project-origin', 'project-origin', [CompletionResultType]::ParameterName, 'Set the project origin')
[CompletionResult]::new('--workdir', 'workdir', [CompletionResultType]::ParameterName, 'Set the working directory')
[CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'Filename extensions to filter to')
Expand Down Expand Up @@ -75,6 76,10 @@ Register-ArgumentCompleter -Native -CommandName 'watchexec' -ScriptBlock {
[CompletionResult]::new('-1', '1', [CompletionResultType]::ParameterName, 'Testing only: exit Watchexec after the first run')
[CompletionResult]::new('-N', 'N ', [CompletionResultType]::ParameterName, 'Alert when commands start and end')
[CompletionResult]::new('--notify', 'notify', [CompletionResultType]::ParameterName, 'Alert when commands start and end')
[CompletionResult]::new('--timings', 'timings', [CompletionResultType]::ParameterName, 'Print how long the command took to run')
[CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Don''t print starting and stopping messages')
[CompletionResult]::new('--quiet', 'quiet', [CompletionResultType]::ParameterName, 'Don''t print starting and stopping messages')
[CompletionResult]::new('--bell', 'bell', [CompletionResultType]::ParameterName, 'Ring the terminal bell on command completion')
[CompletionResult]::new('--no-meta', 'no-meta', [CompletionResultType]::ParameterName, 'Don''t emit fs events for metadata changes')
[CompletionResult]::new('--print-events', 'print-events', [CompletionResultType]::ParameterName, 'Print events that trigger actions')
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Set diagnostic log level')
Expand Down
5 changes: 5 additions & 0 deletions completions/zsh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 33,7 @@ _watchexec() {
'--emit-events-to=[Configure event emission]:MODE:(environment stdin file json-stdin json-file none)' \
'*-E [Add env vars to the command]:KEY=VALUE: ' \
'*--env=[Add env vars to the command]:KEY=VALUE: ' \
'--color=[When to use terminal colours]:MODE:(auto always never)' \
'--project-origin=[Set the project origin]:DIRECTORY:_files -/' \
'--workdir=[Set the working directory]:DIRECTORY:_files -/' \
'*-e [Filename extensions to filter to]:EXTENSIONS: ' \
Expand Down Expand Up @@ -69,6 70,10 @@ _watchexec() {
'-1[Testing only\: exit Watchexec after the first run]' \
'-N[Alert when commands start and end]' \
'--notify[Alert when commands start and end]' \
'--timings[Print how long the command took to run]' \
'-q[Don'\''t print starting and stopping messages]' \
'--quiet[Don'\''t print starting and stopping messages]' \
'--bell[Ring the terminal bell on command completion]' \
'(--fs-events)--no-meta[Don'\''t emit fs events for metadata changes]' \
'--print-events[Print events that trigger actions]' \
'*-v[Set diagnostic log level]' \
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 33,7 @@ is-terminal = "0.4.4"
notify-rust = "4.9.0"
serde_json = "1.0.107"
tempfile = "3.8.1"
termcolor = "1.4.0"
tracing = "0.1.40"
which = "5.0.0"

Expand Down
57 changes: 54 additions & 3 deletions crates/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 7,7 @@ use watchexec_signals::Signal;
const OPTSET_FILTERING: &str = "Filtering";
const OPTSET_COMMAND: &str = "Command";
const OPTSET_DEBUGGING: &str = "Debugging";
const OPTSET_OUTPUT: &str = "Output";

include!(env!("BOSION_PATH"));

Expand Down Expand Up @@ -122,6 123,7 @@ pub struct Args {
#[arg(
short = 'c',
long = "clear",
help_heading = OPTSET_OUTPUT,
num_args = 0..=1,
default_missing_value = "clear",
value_name = "MODE",
Expand Down Expand Up @@ -603,7 605,7 @@ pub struct Args {
/// of the command.
#[arg(
long,
help_heading = OPTSET_COMMAND,
help_heading = OPTSET_OUTPUT,
conflicts_with_all = ["command", "completions", "manual"],
)]
pub only_emit_events: bool,
Expand Down Expand Up @@ -641,9 643,51 @@ pub struct Args {
///
/// With this, Watchexec will emit a desktop notification when a command starts and ends, on
/// supported platforms. On unsupported platforms, it may silently do nothing, or log a warning.
#[arg(long, short = 'N')]
#[arg(
short = 'N',
long,
help_heading = OPTSET_OUTPUT,
)]
pub notify: bool,

/// When to use terminal colours
#[arg(
long,
help_heading = OPTSET_OUTPUT,
default_value = "auto",
value_name = "MODE",
alias = "colour",
)]
pub color: ColourMode,

/// Print how long the command took to run
///
/// This may not be exactly accurate, as it includes some overhead from Watchexec itself. Use
/// the `time` utility, high-precision timers, or benchmarking tools for more accurate results.
#[arg(
long,
help_heading = OPTSET_OUTPUT,
)]
pub timings: bool,

/// Don't print starting and stopping messages
///
/// By default Watchexec will print a message when the command starts and stops. This option
/// disables this behaviour, so only the command's output, warnings, and errors will be printed.
#[arg(
short,
long,
help_heading = OPTSET_OUTPUT,
)]
pub quiet: bool,

/// Ring the terminal bell on command completion
#[arg(
long,
help_heading = OPTSET_OUTPUT,
)]
pub bell: bool,

/// Set the project origin
///
/// Watchexec will attempt to discover the project's "origin" (or "root") by searching for a
Expand Down Expand Up @@ -893,7 937,7 @@ pub enum FsEvent {
Metadata,
}

#[derive(Clone, Copy, Debug, ValueEnum)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub enum ShellCompletion {
Bash,
Elvish,
Expand All @@ -903,6 947,13 @@ pub enum ShellCompletion {
Zsh,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub enum ColourMode {
Auto,
Always,
Never,
}

#[derive(Clone, Copy, Debug)]
pub struct TimeSpan<const UNITLESS_NANOS_MULTIPLIER: u64 = { 1_000_000_000 }>(pub Duration);

Expand Down
Loading