Merge pull request #1171 from tmccombs/clap-derive-comments

Use docstrings for long help in clap derive
This commit is contained in:
David Peter 2022-12-06 22:40:36 +01:00 committed by GitHub
commit 8ecfdfee43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 244 additions and 207 deletions

View File

@ -29,14 +29,15 @@ use crate::filter::SizeFilter;
"max_results", "has_results", "count"])), "max_results", "has_results", "count"])),
)] )]
pub struct Opts { pub struct Opts {
/// Search hidden files and directories /// Include hidden directories and files in the search results (default:
/// hidden files and directories are skipped). Files and directories are
/// considered to be hidden if their name starts with a `.` sign (dot).
/// The flag can be overridden with --no-hidden.
#[arg( #[arg(
long, long,
short = 'H', short = 'H',
long_help = "Include hidden directories and files in the search results (default: \ help = "Search hidden files and directories",
hidden files and directories are skipped). Files and directories are \ long_help
considered to be hidden if their name starts with a `.` sign (dot). \
The flag can be overridden with --no-hidden."
)] )]
pub hidden: bool, pub hidden: bool,
@ -44,13 +45,14 @@ pub struct Opts {
#[arg(long, overrides_with = "hidden", hide = true, action = ArgAction::SetTrue)] #[arg(long, overrides_with = "hidden", hide = true, action = ArgAction::SetTrue)]
no_hidden: (), no_hidden: (),
/// Do not respect .(git|fd)ignore files /// Show search results from files and directories that would otherwise be
/// ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file.
/// The flag can be overridden with --ignore.
#[arg( #[arg(
long, long,
short = 'I', short = 'I',
long_help = "Show search results from files and directories that would otherwise be \ help = "Do not respect .(git|fd)ignore files",
ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file. \ long_help
The flag can be overridden with --ignore."
)] )]
pub no_ignore: bool, pub no_ignore: bool,
@ -58,12 +60,13 @@ pub struct Opts {
#[arg(long, overrides_with = "no_ignore", hide = true, action = ArgAction::SetTrue)] #[arg(long, overrides_with = "no_ignore", hide = true, action = ArgAction::SetTrue)]
ignore: (), ignore: (),
/// Do not respect .gitignore files ///Show search results from files and directories that would otherwise be
/// ignored by '.gitignore' files. The flag can be overridden with --ignore-vcs.
#[arg( #[arg(
long, long,
hide_short_help = true, hide_short_help = true,
long_help = "Show search results from files and directories that would otherwise be \ help = "Do not respect .gitignore files",
ignored by '.gitignore' files. The flag can be overridden with --ignore-vcs." long_help
)] )]
pub no_ignore_vcs: bool, pub no_ignore_vcs: bool,
@ -71,12 +74,13 @@ pub struct Opts {
#[arg(long, overrides_with = "no_ignore_vcs", hide = true, action = ArgAction::SetTrue)] #[arg(long, overrides_with = "no_ignore_vcs", hide = true, action = ArgAction::SetTrue)]
ignore_vcs: (), ignore_vcs: (),
/// Do not respect .(git|fd)ignore files in parent directories /// Show search results from files and directories that would otherwise be
/// ignored by '.gitignore', '.ignore', or '.fdignore' files in parent directories.
#[arg( #[arg(
long, long,
hide_short_help = true, hide_short_help = true,
long_help = "Show search results from files and directories that would otherwise be \ help = "Do not respect .(git|fd)ignore files in parent directories",
ignored by '.gitignore', '.ignore', or '.fdignore' files in parent directories." long_help
)] )]
pub no_ignore_parent: bool, pub no_ignore_parent: bool,
@ -84,10 +88,11 @@ pub struct Opts {
#[arg(long, hide = true)] #[arg(long, hide = true)]
pub no_global_ignore_file: bool, pub no_global_ignore_file: bool,
/// Unrestricted search, alias for '--no-ignore --hidden' /// Perform an unrestricted search, including ignored and hidden files. This is
/// an alias for '--no-ignore --hidden'.
#[arg(long = "unrestricted", short = 'u', overrides_with_all(&["ignore", "no_hidden"]), action(ArgAction::Count), hide_short_help = true, #[arg(long = "unrestricted", short = 'u', overrides_with_all(&["ignore", "no_hidden"]), action(ArgAction::Count), hide_short_help = true,
long_help = "Perform an unrestricted search, including ignored and hidden files. This is \ help = "Unrestricted search, alias for '--no-ignore --hidden'",
an alias for '--no-ignore --hidden'." long_help,
)] )]
rg_alias_hidden_ignore: u8, rg_alias_hidden_ignore: u8,
@ -102,66 +107,72 @@ pub struct Opts {
)] )]
pub case_sensitive: bool, pub case_sensitive: bool,
/// Case-insensitive search (default: smart case) /// Perform a case-insensitive search. By default, fd uses case-insensitive
/// searches, unless the pattern contains an uppercase character (smart
/// case).
#[arg( #[arg(
long, long,
short = 'i', short = 'i',
overrides_with("case_sensitive"), overrides_with("case_sensitive"),
long_help = "Perform a case-insensitive search. By default, fd uses case-insensitive \ help = "Case-insensitive search (default: smart case)",
searches, unless the pattern contains an uppercase character (smart \ long_help
case)."
)] )]
pub ignore_case: bool, pub ignore_case: bool,
/// Glob-based search (default: regular expression) /// Perform a glob-based search instead of a regular expression search.
#[arg( #[arg(
long, long,
short = 'g', short = 'g',
conflicts_with("fixed_strings"), conflicts_with("fixed_strings"),
long_help = "Perform a glob-based search instead of a regular expression search." help = "Glob-based search (default: regular expression)",
long_help
)] )]
pub glob: bool, pub glob: bool,
/// Regular-expression based search (default) /// Perform a regular-expression based search (default). This can be used to
/// override --glob.
#[arg( #[arg(
long, long,
overrides_with("glob"), overrides_with("glob"),
hide_short_help = true, hide_short_help = true,
long_help = "Perform a regular-expression based search (default). This can be used to \ help = "Regular-expression based search (default)",
override --glob." long_help
)] )]
pub regex: bool, pub regex: bool,
/// Treat pattern as literal string stead of regex /// Treat the pattern as a literal string instead of a regular expression. Note
/// that this also performs substring comparison. If you want to match on an
/// exact filename, consider using '--glob'.
#[arg( #[arg(
long, long,
short = 'F', short = 'F',
alias = "literal", alias = "literal",
hide_short_help = true, hide_short_help = true,
long_help = "Treat the pattern as a literal string instead of a regular expression. Note \ help = "Treat pattern as literal string stead of regex",
that this also performs substring comparison. If you want to match on an \ long_help
exact filename, consider using '--glob'."
)] )]
pub fixed_strings: bool, pub fixed_strings: bool,
/// Additional search patterns that need to be matched /// Add additional required search patterns, all of which must be matched. Multiple
/// additional patterns can be specified. The patterns are regular
/// expressions, unless '--glob' or '--fixed-strings' is used.
#[arg( #[arg(
long = "and", long = "and",
value_name = "pattern", value_name = "pattern",
long_help = "Add additional required search patterns, all of which must be matched. Multiple \ help = "Additional search patterns that need to be matched",
additional patterns can be specified. The patterns are regular expressions, \ long_help,
unless '--glob' or '--fixed-strings' is used.",
hide_short_help = true, hide_short_help = true,
allow_hyphen_values = true allow_hyphen_values = true
)] )]
pub exprs: Option<Vec<String>>, pub exprs: Option<Vec<String>>,
/// Show absolute instead of relative paths /// Shows the full path starting from the root as opposed to relative paths.
/// The flag can be overridden with --relative-path.
#[arg( #[arg(
long, long,
short = 'a', short = 'a',
long_help = "Shows the full path starting from the root as opposed to relative paths. \ help = "Show absolute instead of relative paths",
The flag can be overridden with --relative-path." long_help
)] )]
pub absolute_path: bool, pub absolute_path: bool,
@ -169,15 +180,16 @@ pub struct Opts {
#[arg(long, overrides_with = "absolute_path", hide = true, action = ArgAction::SetTrue)] #[arg(long, overrides_with = "absolute_path", hide = true, action = ArgAction::SetTrue)]
relative_path: (), relative_path: (),
/// Use a long listing format with file metadata /// Use a detailed listing format like 'ls -l'. This is basically an alias
/// for '--exec-batch ls -l' with some additional 'ls' options. This can be
/// used to see more metadata, to show symlink targets and to achieve a
/// deterministic sort order.
#[arg( #[arg(
long, long,
short = 'l', short = 'l',
conflicts_with("absolute_path"), conflicts_with("absolute_path"),
long_help = "Use a detailed listing format like 'ls -l'. This is basically an alias \ help = "Use a long listing format with file metadata",
for '--exec-batch ls -l' with some additional 'ls' options. This can be \ long_help
used to see more metadata, to show symlink targets and to achieve a \
deterministic sort order."
)] )]
pub list_details: bool, pub list_details: bool,
@ -196,207 +208,230 @@ pub struct Opts {
#[arg(long, overrides_with = "follow", hide = true, action = ArgAction::SetTrue)] #[arg(long, overrides_with = "follow", hide = true, action = ArgAction::SetTrue)]
no_follow: (), no_follow: (),
/// Search full abs. path (default: filename only) /// By default, the search pattern is only matched against the filename (or directory name). Using this flag, the pattern is matched against the full (absolute) path. Example:
/// fd --glob -p '**/.git/config'
#[arg( #[arg(
long, long,
short = 'p', short = 'p',
long_help = "By default, the search pattern is only matched against the filename (or \ help = "Search full abs. path (default: filename only)",
directory name). Using this flag, the pattern is matched against the full \ long_help,
(absolute) path. Example:\n \ verbatim_doc_comment
fd --glob -p '**/.git/config'"
)] )]
pub full_path: bool, pub full_path: bool,
/// Separate search results by the null character /// Separate search results by the null character (instead of newlines).
/// Useful for piping results to 'xargs'.
#[arg( #[arg(
long = "print0", long = "print0",
short = '0', short = '0',
conflicts_with("list_details"), conflicts_with("list_details"),
hide_short_help = true, hide_short_help = true,
long_help = "Separate search results by the null character (instead of newlines). \ help = "Separate search results by the null character",
Useful for piping results to 'xargs'." long_help
)] )]
pub null_separator: bool, pub null_separator: bool,
/// Set maximum search depth (default: none) /// Limit the directory traversal to a given depth. By default, there is no
/// limit on the search depth.
#[arg( #[arg(
long, long,
short = 'd', short = 'd',
value_name = "depth", value_name = "depth",
alias("maxdepth"), alias("maxdepth"),
long_help = "Limit the directory traversal to a given depth. By default, there is no \ help = "Set maximum search depth (default: none)",
limit on the search depth." long_help
)] )]
max_depth: Option<usize>, max_depth: Option<usize>,
/// Only show search results starting at the given depth. /// Only show search results starting at the given depth.
/// See also: '--max-depth' and '--exact-depth'
#[arg( #[arg(
long, long,
value_name = "depth", value_name = "depth",
hide_short_help = true, hide_short_help = true,
long_help = "Only show search results starting at the given depth. \ help = "Only show search results starting at the given depth.",
See also: '--max-depth' and '--exact-depth'" long_help
)] )]
min_depth: Option<usize>, min_depth: Option<usize>,
/// Only show search results at the exact given depth /// Only show search results at the exact given depth. This is an alias for
/// '--min-depth <depth> --max-depth <depth>'.
#[arg(long, value_name = "depth", hide_short_help = true, conflicts_with_all(&["max_depth", "min_depth"]), #[arg(long, value_name = "depth", hide_short_help = true, conflicts_with_all(&["max_depth", "min_depth"]),
long_help = "Only show search results at the exact given depth. This is an alias for \ help = "Only show search results at the exact given depth",
'--min-depth <depth> --max-depth <depth>'.", long_help,
)] )]
exact_depth: Option<usize>, exact_depth: Option<usize>,
/// Exclude entries that match the given glob pattern /// Exclude files/directories that match the given glob pattern. This
/// overrides any other ignore logic. Multiple exclude patterns can be
/// specified.
///
/// Examples:
/// {n} --exclude '*.pyc'
/// {n} --exclude node_modules
#[arg( #[arg(
long, long,
short = 'E', short = 'E',
value_name = "pattern", value_name = "pattern",
long_help = "Exclude files/directories that match the given glob pattern. This \ help = "Exclude entries that match the given glob pattern",
overrides any other ignore logic. Multiple exclude patterns can be \ long_help
specified.\n\n\
Examples:\n \
--exclude '*.pyc'\n \
--exclude node_modules"
)] )]
pub exclude: Vec<String>, pub exclude: Vec<String>,
/// Do not traverse into directories that match the search criteria. If /// Do not traverse into directories that match the search criteria. If
/// you want to exclude specific directories, use the '--exclude=…' option. /// you want to exclude specific directories, use the '--exclude=…' option.
#[arg(long, hide_short_help = true, conflicts_with_all(&["size", "exact_depth"]), #[arg(long, hide_short_help = true, conflicts_with_all(&["size", "exact_depth"]),
long_help = "Do not traverse into directories that match the search criteria. If \ long_help,
you want to exclude specific directories, use the '--exclude=' option.",
)] )]
pub prune: bool, pub prune: bool,
/// Filter by type: file (f), directory (d), symlink (l), /// Filter the search by type:
/// executable (x), empty (e), socket (s), pipe (p) /// {n} 'f' or 'file': regular files
/// {n} 'd' or 'directory': directories
/// {n} 'l' or 'symlink': symbolic links
/// {n} 's' or 'socket': socket
/// {n} 'p' or 'pipe': named pipe (FIFO)
/// {n}{n} 'x' or 'executable': executables
/// {n} 'e' or 'empty': empty files or directories
///
/// This option can be specified more than once to include multiple file types.
/// Searching for '--type file --type symlink' will show both regular files as
/// well as symlinks. Note that the 'executable' and 'empty' filters work differently:
/// '--type executable' implies '--type file' by default. And '--type empty' searches
/// for empty files and directories, unless either '--type file' or '--type directory'
/// is specified in addition.
///
/// Examples:
/// {n} - Only search for files:
/// {n} fd --type file …
/// {n} fd -tf …
/// {n} - Find both files and symlinks
/// {n} fd --type file --type symlink …
/// {n} fd -tf -tl …
/// {n} - Find executable files:
/// {n} fd --type executable
/// {n} fd -tx
/// {n} - Find empty files:
/// {n} fd --type empty --type file
/// {n} fd -te -tf
/// {n} - Find empty directories:
/// {n} fd --type empty --type directory
/// {n} fd -te -td
#[arg( #[arg(
long = "type", long = "type",
short = 't', short = 't',
value_name = "filetype", value_name = "filetype",
hide_possible_values = true, hide_possible_values = true,
value_enum, value_enum,
long_help = "Filter the search by type:\n \ help = "Filter by type: file (f), directory (d), symlink (l), \
'f' or 'file': regular files\n \ executable (x), empty (e), socket (s), pipe (p)",
'd' or 'directory': directories\n \ long_help
'l' or 'symlink': symbolic links\n \
's' or 'socket': socket\n \
'p' or 'pipe': named pipe (FIFO)\n\n \
'x' or 'executable': executables\n \
'e' or 'empty': empty files or directories\n\n\
This option can be specified more than once to include multiple file types. \
Searching for '--type file --type symlink' will show both regular files as \
well as symlinks. Note that the 'executable' and 'empty' filters work differently: \
'--type executable' implies '--type file' by default. And '--type empty' searches \
for empty files and directories, unless either '--type file' or '--type directory' \
is specified in addition.\n\n\
Examples:\n \
- Only search for files:\n \
fd --type file \n \
fd -tf \n \
- Find both files and symlinks\n \
fd --type file --type symlink \n \
fd -tf -tl \n \
- Find executable files:\n \
fd --type executable\n \
fd -tx\n \
- Find empty files:\n \
fd --type empty --type file\n \
fd -te -tf\n \
- Find empty directories:\n \
fd --type empty --type directory\n \
fd -te -td"
)] )]
pub filetype: Option<Vec<FileType>>, pub filetype: Option<Vec<FileType>>,
/// Filter by file extension /// (Additionally) filter search results by their file extension. Multiple
/// allowable file extensions can be specified.
///
/// If you want to search for files without extension,
/// you can use the regex '^[^.]+$' as a normal search pattern.
#[arg( #[arg(
long = "extension", long = "extension",
short = 'e', short = 'e',
value_name = "ext", value_name = "ext",
long_help = "(Additionally) filter search results by their file extension. Multiple \ help = "Filter by file extension",
allowable file extensions can be specified.\n\ long_help
If you want to search for files without extension, \
you can use the regex '^[^.]+$' as a normal search pattern."
)] )]
pub extensions: Option<Vec<String>>, pub extensions: Option<Vec<String>>,
/// Limit results based on the size of files /// Limit results based on the size of files using the format <+-><NUM><UNIT>.
/// '+': file size must be greater than or equal to this
/// '-': file size must be less than or equal to this
///
/// If neither '+' nor '-' is specified, file size must be exactly equal to this.
/// 'NUM': The numeric size (e.g. 500)
/// 'UNIT': The units for NUM. They are not case-sensitive.
/// Allowed unit values:
/// 'b': bytes
/// 'k': kilobytes (base ten, 10^3 = 1000 bytes)
/// 'm': megabytes
/// 'g': gigabytes
/// 't': terabytes
/// 'ki': kibibytes (base two, 2^10 = 1024 bytes)
/// 'mi': mebibytes
/// 'gi': gibibytes
/// 'ti': tebibytes
#[arg(long, short = 'S', value_parser = SizeFilter::from_string, allow_hyphen_values = true, verbatim_doc_comment, value_name = "size", #[arg(long, short = 'S', value_parser = SizeFilter::from_string, allow_hyphen_values = true, verbatim_doc_comment, value_name = "size",
long_help = "Limit results based on the size of files using the format <+-><NUM><UNIT>.\n \ help = "Limit results based on the size of files",
'+': file size must be greater than or equal to this\n \ long_help,
'-': file size must be less than or equal to this\n\ verbatim_doc_comment,
If neither '+' nor '-' is specified, file size must be exactly equal to this.\n \
'NUM': The numeric size (e.g. 500)\n \
'UNIT': The units for NUM. They are not case-sensitive.\n\
Allowed unit values:\n \
'b': bytes\n \
'k': kilobytes (base ten, 10^3 = 1000 bytes)\n \
'm': megabytes\n \
'g': gigabytes\n \
't': terabytes\n \
'ki': kibibytes (base two, 2^10 = 1024 bytes)\n \
'mi': mebibytes\n \
'gi': gibibytes\n \
'ti': tebibytes",
)] )]
pub size: Vec<SizeFilter>, pub size: Vec<SizeFilter>,
/// Filter by file modification time (newer than) /// Filter results based on the file modification time. Files with modification times
/// greater than the argument are returned. The argument can be provided
/// as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min).
/// If the time is not specified, it defaults to 00:00:00.
/// '--change-newer-than', '--newer', or '--changed-after' can be used as aliases.
///
/// Examples:
/// {n} --changed-within 2weeks
/// {n} --change-newer-than '2018-10-27 10:00:00'
/// {n} --newer 2018-10-27
/// {n} --changed-after 1day
#[arg( #[arg(
long, long,
alias("change-newer-than"), alias("change-newer-than"),
alias("newer"), alias("newer"),
alias("changed-after"), alias("changed-after"),
value_name = "date|dur", value_name = "date|dur",
long_help = "Filter results based on the file modification time. \ help = "Filter by file modification time (newer than)",
Files with modification times greater than the argument are returned. \ long_help
The argument can be provided \
as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min). \
If the time is not specified, it defaults to 00:00:00. \
'--change-newer-than' or '--newer' can be used as aliases.\n\
Examples:\n \
--changed-within 2weeks\n \
--change-newer-than '2018-10-27 10:00:00'\n \
--newer 2018-10-27"
)] )]
pub changed_within: Option<String>, pub changed_within: Option<String>,
/// Filter by file modification time (older than) /// Filter results based on the file modification time. Files with modification times
/// less than the argument are returned. The argument can be provided
/// as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min).
/// '--change-older-than' or '--older' can be used as aliases.
///
/// Examples:
/// {n} --changed-before '2018-10-27 10:00:00'
/// {n} --change-older-than 2weeks
/// {n} --older 2018-10-27
#[arg( #[arg(
long, long,
alias("change-older-than"), alias("change-older-than"),
alias("older"), alias("older"),
value_name = "date|dur", value_name = "date|dur",
long_help = "Filter results based on the file modification time. \ help = "Filter by file modification time (older than)",
Files with modification times less than the argument are returned. \ long_help
The argument can be provided \
as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min). \
'--change-older-than' or '--older' can be used as aliases.\n\
Examples:\n \
--changed-before '2018-10-27 10:00:00'\n \
--change-older-than 2weeks\n \
--older 2018-10-27"
)] )]
pub changed_before: Option<String>, pub changed_before: Option<String>,
/// Filter by owning user and/or group /// Filter files by their user and/or group.
/// Format: [(user|uid)][:(group|gid)]. Either side is optional.
/// Precede either side with a '!' to exclude files instead.
///
/// Examples:
/// {n} --owner john
/// {n} --owner :students
/// {n} --owner '!john:students'
#[cfg(unix)] #[cfg(unix)]
#[arg(long, short = 'o', value_parser = OwnerFilter::from_string, value_name = "user:group", #[arg(long, short = 'o', value_parser = OwnerFilter::from_string, value_name = "user:group",
long_help = "Filter files by their user and/or group. \ help = "Filter by owning user and/or group",
Format: [(user|uid)][:(group|gid)]. Either side is optional. \ long_help,
Precede either side with a '!' to exclude files instead.\n\
Examples:\n \
--owner john\n \
--owner :students\n \
--owner '!john:students'"
)] )]
pub owner: Option<OwnerFilter>, pub owner: Option<OwnerFilter>,
#[command(flatten)] #[command(flatten)]
pub exec: Exec, pub exec: Exec,
/// Max number of arguments to run as a batch size with -X /// Maximum number of arguments to pass to the command given with -X.
/// If the number of results is greater than the given size,
/// the command given with -X is run again with remaining arguments.
/// A batch size of zero means there is no limit (default), but note
/// that batching might still happen due to OS restrictions on the
/// maximum length of command lines.
#[arg( #[arg(
long, long,
value_name = "size", value_name = "size",
@ -404,32 +439,30 @@ pub struct Opts {
requires("exec_batch"), requires("exec_batch"),
value_parser = value_parser!(usize), value_parser = value_parser!(usize),
default_value_t, default_value_t,
long_help = "Maximum number of arguments to pass to the command given with -X. \ help = "Max number of arguments to run as a batch size with -X",
If the number of results is greater than the given size, \ long_help,
the command given with -X is run again with remaining arguments. \
A batch size of zero means there is no limit (default), but note \
that batching might still happen due to OS restrictions on the \
maximum length of command lines.",
)] )]
pub batch_size: usize, pub batch_size: usize,
/// Add a custom ignore-file in '.gitignore' format /// Add a custom ignore-file in '.gitignore' format. These files have a low precedence.
#[arg( #[arg(
long, long,
value_name = "path", value_name = "path",
hide_short_help = true, hide_short_help = true,
long_help = "Add a custom ignore-file in '.gitignore' format. These files have a low precedence." help = "Add a custom ignore-file in '.gitignore' format",
long_help
)] )]
pub ignore_file: Vec<PathBuf>, pub ignore_file: Vec<PathBuf>,
/// When to use colors /// Declare when to use color for the pattern match output
#[arg( #[arg(
long, long,
short = 'c', short = 'c',
value_enum, value_enum,
default_value_t = ColorWhen::Auto, default_value_t = ColorWhen::Auto,
value_name = "when", value_name = "when",
long_help = "Declare when to use color for the pattern match output", help = "When to use colors",
long_help,
)] )]
pub color: ColorWhen, pub color: ColorWhen,
@ -445,100 +478,109 @@ pub struct Opts {
#[arg(long, hide = true, value_parser = parse_millis)] #[arg(long, hide = true, value_parser = parse_millis)]
pub max_buffer_time: Option<Duration>, pub max_buffer_time: Option<Duration>,
/// Limit number of search results ///Limit the number of search results to 'count' and quit immediately.
#[arg( #[arg(
long, long,
value_name = "count", value_name = "count",
hide_short_help = true, hide_short_help = true,
long_help = "Limit the number of search results to 'count' and quit immediately." help = "Limit the number of search results",
long_help
)] )]
max_results: Option<usize>, max_results: Option<usize>,
/// Limit search to a single result /// Limit the search to a single result and quit immediately.
/// This is an alias for '--max-results=1'.
#[arg( #[arg(
short = '1', short = '1',
hide_short_help = true, hide_short_help = true,
overrides_with("max_results"), overrides_with("max_results"),
long_help = "Limit the search to a single result and quit immediately. \ help = "Limit search to a single result",
This is an alias for '--max-results=1'." long_help
)] )]
max_one_result: bool, max_one_result: bool,
/// Print nothing, exit code 0 if match found, 1 otherwise /// When the flag is present, the program does not print anything and will
/// return with an exit code of 0 if there is at least one match. Otherwise, the
/// exit code will be 1.
/// '--has-results' can be used as an alias.
#[arg( #[arg(
long, long,
short = 'q', short = 'q',
alias = "has-results", alias = "has-results",
hide_short_help = true, hide_short_help = true,
conflicts_with("max_results"), conflicts_with("max_results"),
long_help = "When the flag is present, the program does not print anything and will \ help = "Print nothing, exit code 0 if match found, 1 otherwise",
return with an exit code of 0 if there is at least one match. Otherwise, the \ long_help
exit code will be 1. \
'--has-results' can be used as an alias."
)] )]
pub quiet: bool, pub quiet: bool,
/// Show filesystem errors /// Enable the display of filesystem errors for situations such as
/// insufficient permissions or dead symlinks.
#[arg( #[arg(
long, long,
hide_short_help = true, hide_short_help = true,
long_help = "Enable the display of filesystem errors for situations such as \ help = "Show filesystem errors",
insufficient permissions or dead symlinks." long_help
)] )]
pub show_errors: bool, pub show_errors: bool,
/// Change current working directory /// Change the current working directory of fd to the provided path. This
/// means that search results will be shown with respect to the given base
/// path. Note that relative paths which are passed to fd via the positional
/// <path> argument or the '--search-path' option will also be resolved
/// relative to this directory.
#[arg( #[arg(
long, long,
value_name = "path", value_name = "path",
hide_short_help = true, hide_short_help = true,
long_help = "Change the current working directory of fd to the provided path. This \ help = "Change current working directory",
means that search results will be shown with respect to the given base \ long_help
path. Note that relative paths which are passed to fd via the positional \
<path> argument or the '--search-path' option will also be resolved \
relative to this directory."
)] )]
pub base_directory: Option<PathBuf>, pub base_directory: Option<PathBuf>,
/// the search pattern (a regular expression, unless '--glob' is used; optional) /// the search pattern which is either a regular expression (default) or a glob
/// pattern (if --glob is used). If no pattern has been specified, every entry
/// is considered a match. If your pattern starts with a dash (-), make sure to
/// pass '--' first, or it will be considered as a flag (fd -- '-foo').
#[arg( #[arg(
default_value = "", default_value = "",
hide_default_value = true, hide_default_value = true,
value_name = "pattern", value_name = "pattern",
long_help = "the search pattern which is either a regular expression (default) or a glob \ help = "the search pattern (a regular expression, unless '--glob' is used; optional)",
pattern (if --glob is used). If no pattern has been specified, every entry \ long_help
is considered a match. If your pattern starts with a dash (-), make sure to \
pass '--' first, or it will be considered as a flag (fd -- '-foo')."
)] )]
pub pattern: String, pub pattern: String,
/// Set path separator when printing file paths /// Set the path separator to use when printing file paths. The default is
/// the OS-specific separator ('/' on Unix, '\' on Windows).
#[arg( #[arg(
long, long,
value_name = "separator", value_name = "separator",
hide_short_help = true, hide_short_help = true,
long_help = "Set the path separator to use when printing file paths. The default is \ help = "Set path separator when printing file paths",
the OS-specific separator ('/' on Unix, '\\' on Windows)." long_help
)] )]
pub path_separator: Option<String>, pub path_separator: Option<String>,
/// the root directories for the filesystem search (optional) /// The directory where the filesystem search is rooted (optional). If
/// omitted, search the current working directory.
#[arg(action = ArgAction::Append, #[arg(action = ArgAction::Append,
value_name = "path", value_name = "path",
long_help = "The directory where the filesystem search is rooted (optional). If \ help = "the root directories for the filesystem search (optional)",
omitted, search the current working directory.", long_help,
)] )]
path: Vec<PathBuf>, path: Vec<PathBuf>,
/// Provides paths to search as an alternative to the positional <path> argument /// Provide paths to search as an alternative to the positional <path>
/// argument. Changes the usage to `fd [OPTIONS] --search-path <path>
/// --search-path <path2> [<pattern>]`
#[arg( #[arg(
long, long,
conflicts_with("path"), conflicts_with("path"),
value_name = "search-path", value_name = "search-path",
hide_short_help = true, hide_short_help = true,
long_help = "Provide paths to search as an alternative to the positional <path> \ help = "Provides paths to search as an alternative to the positional <path> argument",
argument. Changes the usage to `fd [OPTIONS] --search-path <path> \ long_help
--search-path <path2> [<pattern>]`"
)] )]
search_path: Vec<PathBuf>, search_path: Vec<PathBuf>,
@ -546,20 +588,15 @@ pub struct Opts {
/// -X/--exec-batch, or -0/--print0 are given, to reduce the risk of a /// -X/--exec-batch, or -0/--print0 are given, to reduce the risk of a
/// path starting with '-' being treated as a command line option. Use /// path starting with '-' being treated as a command line option. Use
/// this flag to disable this behaviour. /// this flag to disable this behaviour.
#[arg(long, conflicts_with_all(&["path", "search_path"]), hide_short_help = true, #[arg(long, conflicts_with_all(&["path", "search_path"]), hide_short_help = true, long_help)]
long_help = "By default, relative paths are prefixed with './' when -x/--exec, \
-X/--exec-batch, or -0/--print0 are given, to reduce the risk of a \
path starting with '-' being treated as a command line option. Use \
this flag to disable this behaviour.",
)]
pub strip_cwd_prefix: bool, pub strip_cwd_prefix: bool,
/// By default, fd will traverse the file system tree as far as other options
/// dictate. With this flag, fd ensures that it does not descend into a
/// different file system than the one it started in. Comparable to the -mount
/// or -xdev filters of find(1).
#[cfg(any(unix, windows))] #[cfg(any(unix, windows))]
#[arg(long, aliases(&["mount", "xdev"]), hide_short_help = true, #[arg(long, aliases(&["mount", "xdev"]), hide_short_help = true, long_help)]
long_help = "By default, fd will traverse the file system tree as far as other options \
dictate. With this flag, fd ensures that it does not descend into a \
different file system than the one it started in. Comparable to the -mount \
or -xdev filters of find(1).")]
pub one_file_system: bool, pub one_file_system: bool,
#[cfg(feature = "completions")] #[cfg(feature = "completions")]