Skip to content

Commit 4d8338e

Browse files
committed
feat[completions]: Add value_hints
Add hints for some arguments to generate better completions.
1 parent 2f5ab52 commit 4d8338e

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

src/cli.rs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::time::Duration;
44

55
use anyhow::anyhow;
66
use clap::{
7-
Arg, ArgAction, ArgGroup, ArgMatches, Command, Parser, ValueEnum, error::ErrorKind,
7+
Arg, ArgAction, ArgGroup, ArgMatches, Command, Parser, ValueEnum, ValueHint, error::ErrorKind,
88
value_parser,
99
};
1010
#[cfg(feature = "completions")]
@@ -448,6 +448,7 @@ pub struct Opts {
448448
/// {n} --owner '!john:students'
449449
#[cfg(unix)]
450450
#[arg(long, short = 'o', value_parser = OwnerFilter::from_string, value_name = "user:group",
451+
value_hint = ValueHint::Username,
451452
help = "Filter by owning user and/or group",
452453
long_help,
453454
)]
@@ -492,9 +493,10 @@ pub struct Opts {
492493
#[arg(
493494
long,
494495
value_name = "path",
496+
value_hint = ValueHint::FilePath,
495497
hide_short_help = true,
496498
help = "Add a custom ignore-file in '.gitignore' format",
497-
long_help
499+
long_help,
498500
)]
499501
pub ignore_file: Vec<PathBuf>,
500502

@@ -596,9 +598,10 @@ pub struct Opts {
596598
long,
597599
short = 'C',
598600
value_name = "path",
601+
value_hint = ValueHint::DirPath,
599602
hide_short_help = true,
600603
help = "Change current working directory",
601-
long_help
604+
long_help,
602605
)]
603606
pub base_directory: Option<PathBuf>,
604607

@@ -630,6 +633,7 @@ pub struct Opts {
630633
/// omitted, search the current working directory.
631634
#[arg(action = ArgAction::Append,
632635
value_name = "path",
636+
value_hint = ValueHint::DirPath,
633637
help = "the root directories for the filesystem search (optional)",
634638
long_help,
635639
)]
@@ -642,9 +646,10 @@ pub struct Opts {
642646
long,
643647
conflicts_with("path"),
644648
value_name = "search-path",
649+
value_hint = ValueHint::DirPath,
645650
hide_short_help = true,
646651
help = "Provides paths to search as an alternative to the positional <path> argument",
647-
long_help
652+
long_help,
648653
)]
649654
search_path: Vec<PathBuf>,
650655

@@ -859,34 +864,34 @@ impl clap::Args for Exec {
859864
.long("exec")
860865
.short('x')
861866
.num_args(1..)
862-
.allow_hyphen_values(true)
863-
.value_terminator(";")
864-
.value_name("cmd")
865-
.conflicts_with("list_details")
866-
.help("Execute a command for each search result")
867-
.long_help(
868-
"Execute a command for each search result in parallel (use --threads=1 for sequential command execution). \
869-
There is no guarantee of the order commands are executed in, and the order should not be depended upon. \
870-
All positional arguments following --exec are considered to be arguments to the command - not to fd. \
871-
It is therefore recommended to place the '-x'/'--exec' option last.\n\
872-
The following placeholders are substituted before the command is executed:\n \
873-
'{}': path (of the current search result)\n \
874-
'{/}': basename\n \
875-
'{//}': parent directory\n \
876-
'{.}': path without file extension\n \
877-
'{/.}': basename without file extension\n \
878-
'{{': literal '{' (for escaping)\n \
879-
'}}': literal '}' (for escaping)\n\n\
880-
If no placeholder is present, an implicit \"{}\" at the end is assumed.\n\n\
881-
Examples:\n\n \
882-
- find all *.zip files and unzip them:\n\n \
883-
fd -e zip -x unzip\n\n \
884-
- find *.h and *.cpp files and run \"clang-format -i ..\" for each of them:\n\n \
885-
fd -e h -e cpp -x clang-format -i\n\n \
886-
- Convert all *.jpg files to *.png files:\n\n \
887-
fd -e jpg -x convert {} {.}.png\
888-
",
889-
),
867+
.allow_hyphen_values(true)
868+
.value_terminator(";")
869+
.value_name("cmd")
870+
.conflicts_with("list_details")
871+
.help("Execute a command for each search result")
872+
.long_help(
873+
"Execute a command for each search result in parallel (use --threads=1 for sequential command execution). \
874+
There is no guarantee of the order commands are executed in, and the order should not be depended upon. \
875+
All positional arguments following --exec are considered to be arguments to the command - not to fd. \
876+
It is therefore recommended to place the '-x'/'--exec' option last.\n\
877+
The following placeholders are substituted before the command is executed:\n \
878+
'{}': path (of the current search result)\n \
879+
'{/}': basename\n \
880+
'{//}': parent directory\n \
881+
'{.}': path without file extension\n \
882+
'{/.}': basename without file extension\n \
883+
'{{': literal '{' (for escaping)\n \
884+
'}}': literal '}' (for escaping)\n\n\
885+
If no placeholder is present, an implicit \"{}\" at the end is assumed.\n\n\
886+
Examples:\n\n \
887+
- find all *.zip files and unzip them:\n\n \
888+
fd -e zip -x unzip\n\n \
889+
- find *.h and *.cpp files and run \"clang-format -i ..\" for each of them:\n\n \
890+
fd -e h -e cpp -x clang-format -i\n\n \
891+
- Convert all *.jpg files to *.png files:\n\n \
892+
fd -e jpg -x convert {} {.}.png\
893+
",
894+
),
890895
)
891896
.arg(
892897
Arg::new("exec_batch")

0 commit comments

Comments
 (0)