diff --git a/Cargo.lock b/Cargo.lock index 18c7323..c5dacc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -241,6 +241,8 @@ dependencies = [ "argfile", "assert_cmd", "clap", + "clap_complete", + "clap_complete_fig", "console-subscriber", "dunce", "embed-resource", @@ -309,6 +311,25 @@ dependencies = [ "textwrap", ] +[[package]] +name = "clap_complete" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d044e9db8cd0f68191becdeb5246b7462e4cf0c069b19ae00d1bf3fa9889498d" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_complete_fig" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29cc003d824770d10072f4aa4a958e66d33d74a9cb7339595ac2a445d80d50a0" +dependencies = [ + "clap", + "clap_complete", +] + [[package]] name = "clap_derive" version = "3.0.6" diff --git a/Cargo.toml b/Cargo.toml index 5974caf..85713dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,10 +71,18 @@ embed-resource = "1.6.1" [dev-dependencies] assert_cmd = "1.0.1" +clap_complete = "3.0.4" +clap_complete_fig = "3.0.2" insta = "1.7.1" predicates = "2.0.0" wait-timeout = "0.2.0" +[dev-dependencies.clap] +version = "3.0.10" +features = [ + "derive", +] + [features] dev-console = ["console-subscriber"] @@ -94,17 +102,25 @@ license-file = ["LICENSE", "0"] section = "devel" # conf-files = [] # look me up when config file lands assets = [ - ["target/release/cargo-watch", "usr/bin/", "755"], - ["README.md", "usr/share/doc/cargo-watch/README", "644"], - ["cargo-watch.1", "usr/share/man/man1/cargo-watch.1", "644"], - ["logo.svg", "usr/share/icons/hicolor/scalable/apps/cargo-watch.svg", "644"], + ["target/release/cargo-watch", "usr/bin/", "755"], + ["README.md", "usr/share/doc/cargo-watch/README", "644"], + ["cargo-watch.1", "usr/share/man/man1/cargo-watch.1", "644"], + ["logo.svg", "usr/share/icons/hicolor/scalable/apps/cargo-watch.svg", "644"], + ["completions/cargo-watch.bash", "usr/share/bash-completion/completions/cargo-watch", "644"], + ["completions/cargo-watch.elv", "usr/share/elvish/lib/cargo-watch.elv", "644"], + ["completions/cargo-watch.fish", "usr/share/fish/completions/cargo-watch.fish", "644"], + ["completions/_cargo-watch.zsh", "usr/share/zsh/site-functions/_cargo-watch", "644"], ] [package.metadata.generate-rpm] assets = [ - { source = "target/release/cargo-watch", dest = "/usr/bin/", mode = "755" }, - { source = "README.md", dest = "/usr/share/doc/cargo-watch/README", mode = "644", doc = true }, - { source = "cargo-watch.1", dest = "/usr/share/man/man1/cargo-watch.1.html", mode = "644" }, - { source = "logo.svg", dest = "/usr/share/icons/hicolor/scalable/apps/cargo-watch.svg", mode = "644" }, - # set conf = true for config file when that lands + { source = "target/release/cargo-watch", dest = "/usr/bin/", mode = "755" }, + { source = "README.md", dest = "/usr/share/doc/cargo-watch/README", mode = "644", doc = true }, + { source = "cargo-watch.1", dest = "/usr/share/man/man1/cargo-watch.1.html", mode = "644" }, + { source = "logo.svg", dest = "/usr/share/icons/hicolor/scalable/apps/cargo-watch.svg", mode = "644" }, + { source = "completions/cargo-watch.bash", dest = "usr/share/bash-completion/completions/cargo-watch", mode = "644" }, + { source = "completions/cargo-watch.elv", dest = "/usr/share/elvish/lib/cargo-watch.elv", mode = "644" }, + { source = "completions/cargo-watch.fish", dest = "/usr/share/fish/completions/cargo-watch.fish", mode = "644" }, + { source = "completions/_cargo-watch.zsh", dest = "/usr/share/zsh/site-functions/_cargo-watch", mode = "644" }, + # set conf = true for config file when that lands ] diff --git a/USAGE.md b/USAGE.md index c014763..1827a16 100644 --- a/USAGE.md +++ b/USAGE.md @@ -1,6 +1,8 @@ # Cargo Watch Usage Guide -The `--help` page is always useful locally, as is the manpage on supported systems. +Compact help is available with `-h`, and longer descriptions with `--help`. On +supported systems, a manual page is also available. Shell completions should be +installed for Bash, Elvish, Fig, Fish, Powershell, and Zsh. ## Ignore files diff --git a/bin/complete b/bin/complete new file mode 100755 index 0000000..b190324 --- /dev/null +++ b/bin/complete @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +cargo run --example completions +cd completions +mv _cargo-watch{,.zsh} +mv cargo-watch{,.fig}.ts diff --git a/completions/_cargo-watch.ps1 b/completions/_cargo-watch.ps1 new file mode 100644 index 0000000..1ee578d --- /dev/null +++ b/completions/_cargo-watch.ps1 @@ -0,0 +1,79 @@ + +using namespace System.Management.Automation +using namespace System.Management.Automation.Language + +Register-ArgumentCompleter -Native -CommandName 'cargo-watch' -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + + $commandElements = $commandAst.CommandElements + $command = @( + 'cargo-watch' + for ($i = 1; $i -lt $commandElements.Count; $i++) { + $element = $commandElements[$i] + if ($element -isnot [StringConstantExpressionAst] -or + $element.StringConstantType -ne [StringConstantType]::BareWord -or + $element.Value.StartsWith('-')) { + break + } + $element.Value + }) -join ';' + + $completions = @(switch ($command) { + 'cargo-watch' { + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version information') + [CompletionResult]::new('watch', 'watch', [CompletionResultType]::ParameterValue, 'Watches over your Cargo project’s source') + [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') + break + } + 'cargo-watch;watch' { + [CompletionResult]::new('--features', 'features', [CompletionResultType]::ParameterName, 'Feature(s) passed to cargo invocations') + [CompletionResult]::new('-x', 'x', [CompletionResultType]::ParameterName, 'Cargo command(s) to execute on changes') + [CompletionResult]::new('--exec', 'exec', [CompletionResultType]::ParameterName, 'Cargo command(s) to execute on changes') + [CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Shell command(s) to execute on changes') + [CompletionResult]::new('--shell', 'shell', [CompletionResultType]::ParameterName, 'Shell command(s) to execute on changes') + [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'File updates debounce delay') + [CompletionResult]::new('--delay', 'delay', [CompletionResultType]::ParameterName, 'File updates debounce delay') + [CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'Ignore a path pattern') + [CompletionResult]::new('--ignore', 'ignore', [CompletionResultType]::ParameterName, 'Ignore a path pattern') + [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Reserved for workspace support') + [CompletionResult]::new('--package', 'package', [CompletionResultType]::ParameterName, 'Reserved for workspace support') + [CompletionResult]::new('-w', 'w', [CompletionResultType]::ParameterName, 'Watch specific file(s) or folder(s)') + [CompletionResult]::new('--watch', 'watch', [CompletionResultType]::ParameterName, 'Watch specific file(s) or folder(s)') + [CompletionResult]::new('--use-shell', 'use-shell', [CompletionResultType]::ParameterName, 'Shell to use for the command, or `none` for direct execution') + [CompletionResult]::new('-C', 'C', [CompletionResultType]::ParameterName, 'Change working directory of the command') + [CompletionResult]::new('--workdir', 'workdir', [CompletionResultType]::ParameterName, 'Change working directory of the command') + [CompletionResult]::new('--testing-only--once', 'testing-only--once', [CompletionResultType]::ParameterName, 'testing-only--once') + [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Clear the screen before each run') + [CompletionResult]::new('--clear', 'clear', [CompletionResultType]::ParameterName, 'Clear the screen before each run') + [CompletionResult]::new('--debug', 'debug', [CompletionResultType]::ParameterName, 'Show debug output') + [CompletionResult]::new('--why', 'why', [CompletionResultType]::ParameterName, 'Show paths that changed') + [CompletionResult]::new('--ignore-nothing', 'ignore-nothing', [CompletionResultType]::ParameterName, 'Ignore nothing, not even target/ and .git/') + [CompletionResult]::new('--no-gitignore', 'no-gitignore', [CompletionResultType]::ParameterName, 'Don’t use .gitignore files') + [CompletionResult]::new('--no-ignore', 'no-ignore', [CompletionResultType]::ParameterName, 'Don’t use .ignore files') + [CompletionResult]::new('--no-restart', 'no-restart', [CompletionResultType]::ParameterName, 'Don’t restart command while it’s still running') + [CompletionResult]::new('--all', 'all', [CompletionResultType]::ParameterName, 'Reserves for workspace support') + [CompletionResult]::new('--poll', 'poll', [CompletionResultType]::ParameterName, 'Force use of polling for file changes') + [CompletionResult]::new('--postpone', 'postpone', [CompletionResultType]::ParameterName, 'Postpone first run until a file changes') + [CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Suppress output from cargo watch itself') + [CompletionResult]::new('--quiet', 'quiet', [CompletionResultType]::ParameterName, 'Suppress output from cargo watch itself') + [CompletionResult]::new('-N', 'N', [CompletionResultType]::ParameterName, 'Send a desktop notification on command start and end') + [CompletionResult]::new('--notify', 'notify', [CompletionResultType]::ParameterName, 'Send a desktop notification on command start and end') + [CompletionResult]::new('-B', 'B', [CompletionResultType]::ParameterName, 'Inject RUST_BACKTRACE=value into the command''s environment') + [CompletionResult]::new('-L', 'L', [CompletionResultType]::ParameterName, 'Inject RUST_LOG=value into the command''s environment') + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version information') + break + } + 'cargo-watch;help' { + break + } + }) + + $completions.Where{ $_.CompletionText -like "$wordToComplete*" } | + Sort-Object -Property ListItemText +} diff --git a/completions/_cargo-watch.zsh b/completions/_cargo-watch.zsh new file mode 100644 index 0000000..7ef8c5a --- /dev/null +++ b/completions/_cargo-watch.zsh @@ -0,0 +1,103 @@ +#compdef cargo-watch + +autoload -U is-at-least + +_cargo-watch() { + typeset -A opt_args + typeset -a _arguments_options + local ret=1 + + if is-at-least 5.2; then + _arguments_options=(-s -S -C) + else + _arguments_options=(-s -C) + fi + + local context curcontext="$curcontext" state line + _arguments "${_arguments_options[@]}" \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Print version information]' \ +'--version[Print version information]' \ +":: :_cargo-watch_commands" \ +"*::: :->cargo-watch" \ +&& ret=0 + case $state in + (cargo-watch) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:cargo-watch-command-$line[1]:" + case $line[1] in + (watch) +_arguments "${_arguments_options[@]}" \ +'*--features=[Feature(s) passed to cargo invocations]:FEATURES: ' \ +'*-x+[Cargo command(s) to execute on changes]:cmd: ' \ +'*--exec=[Cargo command(s) to execute on changes]:cmd: ' \ +'*-s+[Shell command(s) to execute on changes]:cmd: ' \ +'*--shell=[Shell command(s) to execute on changes]:cmd: ' \ +'-d+[File updates debounce delay]:DELAY: ' \ +'--delay=[File updates debounce delay]:DELAY: ' \ +'*-i+[Ignore a path pattern]:pattern: ' \ +'*--ignore=[Ignore a path pattern]:pattern: ' \ +'*-p+[Reserved for workspace support]:spec: ' \ +'*--package=[Reserved for workspace support]:spec: ' \ +'*-w+[Watch specific file(s) or folder(s)]:path: ' \ +'*--watch=[Watch specific file(s) or folder(s)]:path: ' \ +'--use-shell=[Shell to use for the command, or `none` for direct execution]:shell: ' \ +'-C+[Change working directory of the command]:path: ' \ +'--workdir=[Change working directory of the command]:path: ' \ +'--testing-only--once[]' \ +'-c[Clear the screen before each run]' \ +'--clear[Clear the screen before each run]' \ +'--debug[Show debug output]' \ +'--why[Show paths that changed]' \ +'--ignore-nothing[Ignore nothing, not even target/ and .git/]' \ +'--no-gitignore[Don’t use .gitignore files]' \ +'--no-ignore[Don’t use .ignore files]' \ +'--no-restart[Don’t restart command while it’s still running]' \ +'--all[Reserves for workspace support]' \ +'--poll[Force use of polling for file changes]' \ +'--postpone[Postpone first run until a file changes]' \ +'-q[Suppress output from cargo watch itself]' \ +'--quiet[Suppress output from cargo watch itself]' \ +'-N[Send a desktop notification on command start and end]' \ +'--notify[Send a desktop notification on command start and end]' \ +'-B[Inject RUST_BACKTRACE=value into the command'\''s environment]' \ +'-L[Inject RUST_LOG=value into the command'\''s environment]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Print version information]' \ +'--version[Print version information]' \ +'*::cmd-trail -- Full command to run. -x and -s will be ignored!:' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +'*::subcommand -- The subcommand whose help message to display:' \ +&& ret=0 +;; + esac + ;; +esac +} + +(( $+functions[_cargo-watch_commands] )) || +_cargo-watch_commands() { + local commands; commands=( +'watch:Watches over your Cargo project’s source' \ +'help:Print this message or the help of the given subcommand(s)' \ + ) + _describe -t commands 'cargo-watch commands' commands "$@" +} +(( $+functions[_cargo-watch__help_commands] )) || +_cargo-watch__help_commands() { + local commands; commands=() + _describe -t commands 'cargo-watch help commands' commands "$@" +} +(( $+functions[_cargo-watch__watch_commands] )) || +_cargo-watch__watch_commands() { + local commands; commands=() + _describe -t commands 'cargo-watch watch commands' commands "$@" +} + +_cargo-watch "$@" diff --git a/completions/cargo-watch.bash b/completions/cargo-watch.bash new file mode 100644 index 0000000..70098f9 --- /dev/null +++ b/completions/cargo-watch.bash @@ -0,0 +1,136 @@ +_cargo-watch() { + local i cur prev opts cmds + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + cmd="" + opts="" + + for i in ${COMP_WORDS[@]} + do + case "${i}" in + "$1") + cmd="cargo__watch" + ;; + help) + cmd+="__help" + ;; + watch) + cmd+="__watch" + ;; + *) + ;; + esac + done + + case "${cmd}" in + cargo__watch) + opts="-h -V --help --version watch help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + cargo__watch__help) + opts="..." + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + cargo__watch__watch) + opts="-c -q -x -s -d -i -p -w -C -N -B -L -h -V --testing-only--once --clear --debug --why --ignore-nothing --no-gitignore --no-ignore --no-restart --all --poll --postpone --features --quiet --exec --shell --delay --ignore --package --watch --use-shell --workdir --notify --help --version ..." + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + --features) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --exec) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -x) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --shell) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -s) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --delay) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -d) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --ignore) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -i) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --package) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -p) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --watch) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -w) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --use-shell) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --workdir) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -C) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + esac +} + +complete -F _cargo-watch -o bashdefault -o default cargo-watch diff --git a/completions/cargo-watch.elv b/completions/cargo-watch.elv new file mode 100644 index 0000000..092fb3b --- /dev/null +++ b/completions/cargo-watch.elv @@ -0,0 +1,72 @@ + +use builtin; +use str; + +set edit:completion:arg-completer[cargo-watch] = {|@words| + fn spaces {|n| + builtin:repeat $n ' ' | str:join '' + } + fn cand {|text desc| + edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc + } + var command = 'cargo-watch' + for word $words[1..-1] { + if (str:has-prefix $word '-') { + break + } + set command = $command';'$word + } + var completions = [ + &'cargo-watch'= { + cand -h 'Print help information' + cand --help 'Print help information' + cand -V 'Print version information' + cand --version 'Print version information' + cand watch 'Watches over your Cargo project’s source' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'cargo-watch;watch'= { + cand --features 'Feature(s) passed to cargo invocations' + cand -x 'Cargo command(s) to execute on changes' + cand --exec 'Cargo command(s) to execute on changes' + cand -s 'Shell command(s) to execute on changes' + cand --shell 'Shell command(s) to execute on changes' + cand -d 'File updates debounce delay' + cand --delay 'File updates debounce delay' + cand -i 'Ignore a path pattern' + cand --ignore 'Ignore a path pattern' + cand -p 'Reserved for workspace support' + cand --package 'Reserved for workspace support' + cand -w 'Watch specific file(s) or folder(s)' + cand --watch 'Watch specific file(s) or folder(s)' + cand --use-shell 'Shell to use for the command, or `none` for direct execution' + cand -C 'Change working directory of the command' + cand --workdir 'Change working directory of the command' + cand --testing-only--once 'testing-only--once' + cand -c 'Clear the screen before each run' + cand --clear 'Clear the screen before each run' + cand --debug 'Show debug output' + cand --why 'Show paths that changed' + cand --ignore-nothing 'Ignore nothing, not even target/ and .git/' + cand --no-gitignore 'Don’t use .gitignore files' + cand --no-ignore 'Don’t use .ignore files' + cand --no-restart 'Don’t restart command while it’s still running' + cand --all 'Reserves for workspace support' + cand --poll 'Force use of polling for file changes' + cand --postpone 'Postpone first run until a file changes' + cand -q 'Suppress output from cargo watch itself' + cand --quiet 'Suppress output from cargo watch itself' + cand -N 'Send a desktop notification on command start and end' + cand --notify 'Send a desktop notification on command start and end' + cand -B 'Inject RUST_BACKTRACE=value into the command''s environment' + cand -L 'Inject RUST_LOG=value into the command''s environment' + cand -h 'Print help information' + cand --help 'Print help information' + cand -V 'Print version information' + cand --version 'Print version information' + } + &'cargo-watch;help'= { + } + ] + $completions[$command] +} diff --git a/completions/cargo-watch.fig.ts b/completions/cargo-watch.fig.ts new file mode 100644 index 0000000..361e0f1 --- /dev/null +++ b/completions/cargo-watch.fig.ts @@ -0,0 +1,183 @@ +const completion: Fig.Spec = { + name: "cargo-watch", + description: "", + subcommands: [ + { + name: "watch", + description: "Watches over your Cargo project’s source", + options: [ + { + name: "--features", + description: "Feature(s) passed to cargo invocations", + args: { + name: "features", + isOptional: true, + }, + }, + { + name: ["-x", "--exec"], + description: "Cargo command(s) to execute on changes", + args: { + name: "cmd-cargo", + isVariadic: true, + isOptional: true, + }, + }, + { + name: ["-s", "--shell"], + description: "Shell command(s) to execute on changes", + args: { + name: "cmd-shell", + isVariadic: true, + isOptional: true, + }, + }, + { + name: ["-d", "--delay"], + description: "File updates debounce delay", + args: { + name: "delay", + isOptional: true, + }, + }, + { + name: ["-i", "--ignore"], + description: "Ignore a path pattern", + args: { + name: "ignores", + isVariadic: true, + isOptional: true, + }, + }, + { + name: ["-p", "--package"], + description: "Reserved for workspace support", + args: { + name: "packages-specs", + isVariadic: true, + isOptional: true, + }, + }, + { + name: ["-w", "--watch"], + description: "Watch specific file(s) or folder(s)", + args: { + name: "watch", + isVariadic: true, + isOptional: true, + }, + }, + { + name: "--use-shell", + description: "Shell to use for the command, or `none` for direct execution", + args: { + name: "shell", + isOptional: true, + }, + }, + { + name: ["-C", "--workdir"], + description: "Change working directory of the command", + args: { + name: "workdir", + isOptional: true, + }, + }, + { + name: "--testing-only--once", + }, + { + name: ["-c", "--clear"], + description: "Clear the screen before each run", + }, + { + name: "--debug", + description: "Show debug output", + }, + { + name: "--why", + description: "Show paths that changed", + }, + { + name: "--ignore-nothing", + description: "Ignore nothing, not even target/ and .git/", + }, + { + name: "--no-gitignore", + description: "Don’t use .gitignore files", + }, + { + name: "--no-ignore", + description: "Don’t use .ignore files", + }, + { + name: "--no-restart", + description: "Don’t restart command while it’s still running", + }, + { + name: "--all", + description: "Reserves for workspace support", + }, + { + name: "--poll", + description: "Force use of polling for file changes", + }, + { + name: "--postpone", + description: "Postpone first run until a file changes", + }, + { + name: ["-q", "--quiet"], + description: "Suppress output from cargo watch itself", + }, + { + name: ["-N", "--notify"], + description: "Send a desktop notification on command start and end", + }, + { + name: "-B", + description: "Inject RUST_BACKTRACE=value into the command's environment", + }, + { + name: "-L", + description: "Inject RUST_LOG=value into the command's environment", + }, + { + name: ["-h", "--help"], + description: "Print help information", + }, + { + name: ["-V", "--version"], + description: "Print version information", + }, + ], + args: { + name: "cmd-trail", + isVariadic: true, + isOptional: true, + }, + }, + { + name: "help", + description: "Print this message or the help of the given subcommand(s)", + options: [ + ], + args: { + name: "subcommand", + isOptional: true, + }, + }, + ], + options: [ + { + name: ["-h", "--help"], + description: "Print help information", + }, + { + name: ["-V", "--version"], + description: "Print version information", + }, + ], +}; + +export default completion; diff --git a/completions/cargo-watch.fish b/completions/cargo-watch.fish new file mode 100644 index 0000000..c4f1687 --- /dev/null +++ b/completions/cargo-watch.fish @@ -0,0 +1,30 @@ +complete -c cargo-watch -n "__fish_use_subcommand" -s h -l help -d 'Print help information' +complete -c cargo-watch -n "__fish_use_subcommand" -s V -l version -d 'Print version information' +complete -c cargo-watch -n "__fish_use_subcommand" -f -a "watch" -d 'Watches over your Cargo project’s source' +complete -c cargo-watch -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l features -d 'Feature(s) passed to cargo invocations' -r +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s x -l exec -d 'Cargo command(s) to execute on changes' -r +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s s -l shell -d 'Shell command(s) to execute on changes' -r +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s d -l delay -d 'File updates debounce delay' -r +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s i -l ignore -d 'Ignore a path pattern' -r +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s p -l package -d 'Reserved for workspace support' -r +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s w -l watch -d 'Watch specific file(s) or folder(s)' -r +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l use-shell -d 'Shell to use for the command, or `none` for direct execution' -r +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s C -l workdir -d 'Change working directory of the command' -r +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l testing-only--once +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s c -l clear -d 'Clear the screen before each run' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l debug -d 'Show debug output' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l why -d 'Show paths that changed' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l ignore-nothing -d 'Ignore nothing, not even target/ and .git/' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l no-gitignore -d 'Don’t use .gitignore files' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l no-ignore -d 'Don’t use .ignore files' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l no-restart -d 'Don’t restart command while it’s still running' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l all -d 'Reserves for workspace support' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l poll -d 'Force use of polling for file changes' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -l postpone -d 'Postpone first run until a file changes' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s q -l quiet -d 'Suppress output from cargo watch itself' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s N -l notify -d 'Send a desktop notification on command start and end' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s B -d 'Inject RUST_BACKTRACE=value into the command\'s environment' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s L -d 'Inject RUST_LOG=value into the command\'s environment' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s h -l help -d 'Print help information' +complete -c cargo-watch -n "__fish_seen_subcommand_from watch" -s V -l version -d 'Print version information' diff --git a/completions/zsh b/completions/zsh deleted file mode 100644 index 88232a7..0000000 --- a/completions/zsh +++ /dev/null @@ -1,38 +0,0 @@ -#compdef cargo-watch - -setopt localoptions extended_glob - -local cmd -local -a args -local -a _comp_priv_prefix - -cmd="$words[1]" - -args=( - '(-c --clear)'{-c,--clear}'[Clear screen before executing command]' - '(-h --help)'{-h,--help}'[Print help information]' - '(-V --version)'{-V,--version}'[Print version information]' - '(-x --exec)'{-x+,--exec=}'[Cargo subcommand to execute on changes]:cargo-command' - '(-s --shell)'{-s+,--shell=}'[Shell command to execute on changes]:command' - '(-i --ignore)'{-i+,--ignore=}'[Ignore changes to paths matching the pattern]:pattern' - '(-w --watch)'{-w+,--watch=}'[Watch a specific directory]:path:_path_files -/' - '(-C --workdir)'{-C+,--workdir=}'[Change working directory of command]:path:_path_files -/' - '-B=[Inject RUST_BACKTRACE=value into the environment]:value' - '--no-ignore[Skip .ignore files]' - '--no-gitignore[Skip .gitignore files]' - '--ignore-nothing[Ignore nothing, not even target/ and .git/]' - '--use-shell=[Change the wrapping shell]:program' - '--postpone[Wait until first change to execute command]' - '--no-restart[Do not restart while the command isstill running]' - '--watch-when-idle[Ignore events while the command is still running]' - '--quiet[Suppress all cargo-watch output]' - '--debug[Print debugging to stderr]' - '--why[Print changed paths to stderr]' - '--delay=[File updates debounce delay]:seconds' - '--poll=[Forces polling mode]:interval' - '--features=[List of features passed to cargo invocations]:features' - '(-)1:command: _command_names -e' - '*::arguments:{ _comp_priv_prefix=( $cmd -n ${(kv)opt_args[-u]} ) ; _normal }' -) - -_arguments -s -S $args diff --git a/examples/completions.rs b/examples/completions.rs new file mode 100644 index 0000000..ea04339 --- /dev/null +++ b/examples/completions.rs @@ -0,0 +1,25 @@ +use clap::IntoApp; +use clap_complete::{generate_to, shells::*, Generator}; +use clap_complete_fig::Fig; +use std::io::Error; + +#[path = "../src/args.rs"] +mod args; + +fn main() -> Result<(), Error> { + gen_help(Bash)?; + gen_help(Elvish)?; + gen_help(Fig)?; + gen_help(Fish)?; + gen_help(PowerShell)?; + gen_help(Zsh)?; + + Ok(()) +} + +fn gen_help(gen: impl Generator) -> Result<(), Error> { + let mut app = args::App::into_app(); + let path = generate_to(gen, &mut app, "cargo-watch", "./completions/")?; + println!("completion file is generated: {:?}", path); + Ok(()) +} diff --git a/src/args.rs b/src/args.rs index f291e54..8ff629c 100644 --- a/src/args.rs +++ b/src/args.rs @@ -12,14 +12,14 @@ const OPTSET_WORKSPACES: &str = "WORKSPACES"; #[derive(Debug, Clone, Parser)] #[clap(name = "cargo-watch", bin_name = "cargo", version)] -struct App { +pub struct App { #[clap(subcommand)] - command: Command, + pub command: Command, } #[derive(Debug, Clone, clap::Subcommand)] #[clap(name = "cargo-watch", bin_name = "cargo", version)] -enum Command { +pub enum Command { #[clap(name = "watch")] Watch(Args), } @@ -221,12 +221,3 @@ pub struct Args { #[clap(raw = true, value_name = "trailing command", help_heading = OPTSET_COMMAND)] pub cmd_trail: Option, } - -pub fn get_args() -> Args { - let args = wild::args_os(); - let args = argfile::expand_args_from(args, argfile::parse_fromfile, argfile::PREFIX).unwrap(); - - let app = App::parse_from(args); - let Command::Watch(args) = app.command; - args -} diff --git a/src/config.rs b/src/config.rs index 200a573..6ab7c74 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,17 @@ +pub use init::init; +pub use runtime::runtime; + +use crate::args::*; +use clap::Parser; + mod init; mod runtime; -pub use init::init; -pub use runtime::runtime; +pub fn get_args() -> Args { + let args = wild::args_os(); + let args = argfile::expand_args_from(args, argfile::parse_fromfile, argfile::PREFIX).unwrap(); + + let app = App::parse_from(args); + let Command::Watch(args) = app.command; + args +} diff --git a/src/main.rs b/src/main.rs index 8041b8a..dfe3c43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ async fn main() -> Result<()> { tracing_subscriber::fmt::init(); } - let args = args::get_args(); + let args = config::get_args(); { // TODO