From d91f41750d22c5ac222a248daa7d552e10909fc1 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Mon, 17 Oct 2022 20:40:21 +0700 Subject: [PATCH] Improve shell completions --- exports/completion.fish | 2 +- exports/completion.zsh | 6 +++--- src/cli_opt.rs | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/exports/completion.fish b/exports/completion.fish index 43e0a41..2454b68 100644 --- a/exports/completion.fish +++ b/exports/completion.fish @@ -1,7 +1,7 @@ complete -c sane-fmt -l details -d 'File diff detail' -r -f -a "{count ,name ,diff }" complete -c sane-fmt -l color -d 'When to use terminal color' -r -f -a "{auto ,never ,always }" complete -c sane-fmt -l log-format -d 'Format of log messages' -r -f -a "{human ,github-actions }" -complete -c sane-fmt -s I -l include -d 'Files whose contents contain paths to target files (`-` means stdin, other strings mean text file)' -r +complete -c sane-fmt -s I -l include -d 'Files whose contents contain paths to target files (`-` means stdin, other strings mean text file)' -r -F complete -c sane-fmt -l stdio -d 'Reads unformatted code from standard input, prints formatted code to standard output, then exits' complete -c sane-fmt -s w -l write -d 'Whether to write or check' complete -c sane-fmt -l hide-passed -d 'Do not log passed filenames' diff --git a/exports/completion.zsh b/exports/completion.zsh index b6090f9..71f4b34 100644 --- a/exports/completion.zsh +++ b/exports/completion.zsh @@ -18,8 +18,8 @@ _sane-fmt() { '--details=[File diff detail]:DETAILS:(count name diff)' \ '--color=[When to use terminal color]:COLOR:(auto never always)' \ '--log-format=[Format of log messages]:LOG_FORMAT:(human github-actions)' \ -'-I+[Files whose contents contain paths to target files (`-` means stdin, other strings mean text file)]:INCLUDE: ' \ -'--include=[Files whose contents contain paths to target files (`-` means stdin, other strings mean text file)]:INCLUDE: ' \ +'-I+[Files whose contents contain paths to target files (`-` means stdin, other strings mean text file)]:INCLUDE:_files' \ +'--include=[Files whose contents contain paths to target files (`-` means stdin, other strings mean text file)]:INCLUDE:_files' \ '--stdio[Reads unformatted code from standard input, prints formatted code to standard output, then exits]' \ '-w[Whether to write or check]' \ '--write[Whether to write or check]' \ @@ -28,7 +28,7 @@ _sane-fmt() { '--help[Print help information (use `--help` for more detail)]' \ '-V[Print version information]' \ '--version[Print version information]' \ -'*::files -- Files to process:' \ +'*::files -- Files to process:_files' \ && ret=0 } diff --git a/src/cli_opt.rs b/src/cli_opt.rs index c29fc33..4be050a 100644 --- a/src/cli_opt.rs +++ b/src/cli_opt.rs @@ -8,7 +8,7 @@ pub use input_stream_address::*; pub use log_format::*; pub use when::*; -use clap::Parser; +use clap::{Parser, ValueHint}; /// Opinionated code formatter for TypeScript and JavaScript #[derive(Debug, Parser)] @@ -41,11 +41,12 @@ pub struct CliOpt { /// Files whose contents contain paths to target files /// (`-` means stdin, other strings mean text file) - #[clap(long, short = 'I')] + #[clap(long, short = 'I', value_hint = ValueHint::FilePath)] pub include: Option, /// Files to process /// /// If none are provided, a default set of files will be assumed + #[clap(value_hint = ValueHint::AnyPath)] pub files: Vec, }