Struct rg::args::ArgMatches

source ·
struct ArgMatches(ArgMatches<'static>);
Expand description

ArgMatches wraps clap::ArgMatches and provides semantic meaning to the parsed arguments.

Tuple Fields§

§0: ArgMatches<'static>

Implementations§

source§

impl ArgMatches

source

fn new(clap_matches: ArgMatches<'static>) -> ArgMatches

Create an ArgMatches from clap’s parse result.

source

fn reconfigure(self) -> Result<ArgMatches, Box<dyn Error>>

Run clap and return the matches using a config file if present. If clap determines a problem with the user provided arguments (or if –help or –version are given), then an error/usage/version will be printed and the process will exit.

If there are no additional arguments from the environment (e.g., a config file), then the given matches are returned as is.

source

fn to_args(self) -> Result<Args, Box<dyn Error>>

Convert the result of parsing CLI arguments into ripgrep’s higher level configuration structure.

source§

impl ArgMatches

High level routines for converting command line arguments into various data structures used by ripgrep.

Methods are sorted alphabetically.

source

fn matcher(&self, patterns: &[String]) -> Result<PatternMatcher, Box<dyn Error>>

Return the matcher that should be used for searching.

If there was a problem building the matcher (e.g., a syntax error), then this returns an error.

source

fn matcher_engine( &self, engine: &str, patterns: &[String] ) -> Result<PatternMatcher, Box<dyn Error>>

Return the matcher that should be used for searching using engine as the engine for the patterns.

If there was a problem building the matcher (e.g., a syntax error), then this returns an error.

source

fn matcher_rust( &self, patterns: &[String] ) -> Result<RustRegexMatcher, Box<dyn Error>>

Build a matcher using Rust’s regex engine.

If there was a problem building the matcher (such as a regex syntax error), then an error is returned.

source

fn printer_json<W: Write>(&self, wtr: W) -> Result<JSON<W>, Box<dyn Error>>

Build a JSON printer that writes results to the given writer.

source

fn printer_standard<W: WriteColor>( &self, paths: &[PathBuf], wtr: W, separator_search: bool ) -> Result<Standard<W>, Box<dyn Error>>

Build a Standard printer that writes results to the given writer.

The given paths are used to configure aspects of the printer.

If separator_search is true, then the returned printer will assume the responsibility of printing a separator between each set of search results, when appropriate (e.g., when contexts are enabled). When it’s set to false, the caller is responsible for handling separators.

In practice, we want the printer to handle it in the single threaded case but not in the multi-threaded case.

source

fn printer_summary<W: WriteColor>( &self, paths: &[PathBuf], wtr: W ) -> Result<Summary<W>, Box<dyn Error>>

Build a Summary printer that writes results to the given writer.

The given paths are used to configure aspects of the printer.

This panics if the output format is not OutputKind::Summary.

source

fn searcher(&self, paths: &[PathBuf]) -> Result<Searcher, Box<dyn Error>>

Build a searcher from the command line parameters.

source

fn walker_builder( &self, paths: &[PathBuf], threads: usize ) -> Result<WalkBuilder, Box<dyn Error>>

Return a builder for recursively traversing a directory while respecting ignore rules.

If there was a problem parsing the CLI arguments necessary for constructing the builder, then this returns an error.

source§

impl ArgMatches

Mid level routines for converting command line arguments into various types of data structures.

Methods are sorted alphabetically.

source

fn binary_detection_implicit(&self) -> BinaryDetection

Returns the form of binary detection to perform on files that are implicitly searched via recursive directory traversal.

source

fn binary_detection_explicit(&self) -> BinaryDetection

Returns the form of binary detection to perform on files that are explicitly searched via the user invoking ripgrep on a particular file or files or stdin.

In general, this should never be BinaryDetection::quit, since that acts as a filter (but quitting immediately once a NUL byte is seen), and we should never filter out files that the user wants to explicitly search.

source

fn can_never_match(&self, patterns: &[String]) -> bool

Returns true if the command line configuration implies that a match can never be shown.

source

fn case_insensitive(&self) -> bool

Returns true if and only if case should be ignore.

If –case-sensitive is present, then case is never ignored, even if –ignore-case is present.

source

fn case_smart(&self) -> bool

Returns true if and only if smart case has been enabled.

If either –ignore-case of –case-sensitive are present, then smart case is disabled.

source

fn color_choice(&self) -> ColorChoice

Returns the user’s color choice based on command line parameters and environment.

source

fn color_specs(&self) -> Result<ColorSpecs, Box<dyn Error>>

Returns the color specifications given by the user on the CLI.

If the was a problem parsing any of the provided specs, then an error is returned.

source

fn column(&self) -> bool

Returns true if and only if column numbers should be shown.

source

fn contexts(&self) -> Result<(usize, usize), Box<dyn Error>>

Returns the before and after contexts from the command line.

If a context setting was absent, then 0 is returned.

If there was a problem parsing the values from the user as an integer, then an error is returned.

source

fn context_separator(&self) -> Option<Vec<u8>>

Returns the unescaped context separator in UTF-8 bytes.

If one was not provided, the default -- is returned. If –no-context-separator is passed, None is returned.

source

fn counts(&self) -> (bool, bool)

Returns whether the -c/–count or the –count-matches flags were passed from the command line.

If –count-matches and –invert-match were passed in, behave as if –count and –invert-match were passed in (i.e. rg will count inverted matches as per existing behavior).

source

fn dfa_size_limit(&self) -> Result<Option<usize>, Box<dyn Error>>

Parse the dfa-size-limit argument option into a byte count.

source

fn encoding(&self) -> Result<EncodingMode, Box<dyn Error>>

Returns the encoding mode to use.

This only returns an encoding if one is explicitly specified. Otherwise if set to automatic, the Searcher will do BOM sniffing for UTF-16 and transcode seamlessly. If disabled, no BOM sniffing nor transcoding will occur.

source

fn file_separator(&self) -> Result<Option<Vec<u8>>, Box<dyn Error>>

Return the file separator to use based on the CLI configuration.

source

fn heading(&self) -> bool

Returns true if and only if matches should be grouped with file name headings.

source

fn hidden(&self) -> bool

Returns true if and only if hidden files/directories should be searched.

Returns the hyperlink pattern to use. A default pattern suitable for the current system is used if the value is not set.

If an invalid pattern is provided, then an error is returned.

source

fn ignore_file_case_insensitive(&self) -> bool

Returns true if ignore files should be processed case insensitively.

source

fn ignore_paths(&self) -> Vec<PathBuf>

Return all of the ignore file paths given on the command line.

Returns true if and only if ripgrep is invoked in a way where it knows it search exactly one thing.

source

fn is_only_stdin(&self, paths: &[PathBuf]) -> bool

Returns true if and only if we’re only searching a single thing and that thing is stdin.

source

fn line_number(&self, paths: &[PathBuf]) -> bool

Returns true if and only if we should show line numbers.

source

fn max_columns(&self) -> Result<Option<u64>, Box<dyn Error>>

The maximum number of columns allowed on each line.

If 0 is provided, then this returns None.

source

fn max_columns_preview(&self) -> bool

Returns true if and only if a preview should be shown for lines that exceed the maximum column limit.

source

fn max_count(&self) -> Result<Option<u64>, Box<dyn Error>>

The maximum number of matches permitted.

source

fn max_file_size(&self) -> Result<Option<u64>, Box<dyn Error>>

Parses the max-filesize argument option into a byte count.

source

fn mmap_choice(&self, paths: &[PathBuf]) -> MmapChoice

Returns whether we should attempt to use memory maps or not.

source

fn no_ignore(&self) -> bool

Returns true if ignore files should be ignored.

source

fn no_ignore_dot(&self) -> bool

Returns true if .ignore files should be ignored.

source

fn no_ignore_exclude(&self) -> bool

Returns true if local exclude (ignore) files should be ignored.

source

fn no_ignore_files(&self) -> bool

Returns true if explicitly given ignore files should be ignored.

source

fn no_ignore_global(&self) -> bool

Returns true if global ignore files should be ignored.

source

fn no_ignore_parent(&self) -> bool

Returns true if parent ignore files should be ignored.

source

fn no_ignore_vcs(&self) -> bool

Returns true if VCS ignore files should be ignored.

source

fn output_kind(&self) -> OutputKind

Determine the type of output we should produce.

source

fn overrides(&self) -> Result<Override, Box<dyn Error>>

Builds the set of glob overrides from the command line flags.

source

fn paths(&self) -> Vec<PathBuf>

Return all file paths that ripgrep should search.

If no paths were given, then this returns an empty list.

source

fn path_default(&self) -> PathBuf

Return the default path that ripgrep should search. This should only be used when ripgrep is not otherwise given at least one file path as a positional argument.

source

fn path_separator(&self) -> Result<Option<u8>, Box<dyn Error>>

Returns the unescaped path separator as a single byte, if one exists.

If the provided path separator is more than a single byte, then an error is returned.

source

fn path_terminator(&self) -> Option<u8>

Returns the byte that should be used to terminate paths.

Typically, this is only set to \x00 when the –null flag is provided, and None otherwise.

source

fn field_context_separator(&self) -> Vec<u8>

Returns the unescaped field context separator. If one wasn’t specified, then ‘-’ is used as the default.

source

fn field_match_separator(&self) -> Vec<u8>

Returns the unescaped field match separator. If one wasn’t specified, then ‘:’ is used as the default.

source

fn patterns(&self) -> Result<Vec<String>, Box<dyn Error>>

Get a sequence of all available patterns from the command line. This includes reading the -e/–regexp and -f/–file flags.

If any pattern is invalid UTF-8, then an error is returned.

source

fn pattern_from_os_str(&self, pat: &OsStr) -> Result<String, Box<dyn Error>>

Converts an OsStr pattern to a String pattern. The pattern is escaped if -F/–fixed-strings is set.

If the pattern is not valid UTF-8, then an error is returned.

source

fn pattern_from_str(&self, pat: &str) -> String

Converts a &str pattern to a String pattern. The pattern is escaped if -F/–fixed-strings is set.

source

fn pattern_from_string(&self, pat: String) -> String

Applies additional processing on the given pattern if necessary (such as escaping meta characters or turning it into a line regex).

source

fn preprocessor(&self) -> Option<PathBuf>

Returns the preprocessor command if one was specified.

source

fn preprocessor_globs(&self) -> Result<Override, Box<dyn Error>>

Builds the set of globs for filtering files to apply to the –pre flag. If no –pre-globs are available, then this always returns an empty set of globs.

source

fn regex_size_limit(&self) -> Result<Option<usize>, Box<dyn Error>>

Parse the regex-size-limit argument option into a byte count.

source

fn replacement(&self) -> Option<Vec<u8>>

Returns the replacement string as UTF-8 bytes if it exists.

source

fn sort_by(&self) -> Result<SortBy, Box<dyn Error>>

Returns the sorting criteria based on command line parameters.

source

fn stats(&self) -> bool

Returns true if and only if aggregate statistics for a search should be tracked.

Generally, this is only enabled when explicitly requested by in the command line arguments via the –stats flag, but this can also be enabled implicitly via the output format, e.g., for JSON Lines.

source

fn summary_kind(&self) -> Option<SummaryKind>

When the output format is Summary, this returns the type of summary output to show.

This returns None if the output format is not Summary.

source

fn threads(&self) -> Result<usize, Box<dyn Error>>

Return the number of threads that should be used for parallelism.

source

fn types(&self) -> Result<Types, Box<dyn Error>>

Builds a file type matcher from the command line flags.

source

fn unrestricted_count(&self) -> u64

Returns the number of times the unrestricted flag is provided.

source

fn unicode(&self) -> bool

Returns true if and only if Unicode mode should be enabled.

source

fn with_filename(&self, paths: &[PathBuf]) -> bool

Returns true if and only if file names containing each match should be emitted.

source§

impl ArgMatches

Lower level generic helper methods for teasing values out of clap.

source

fn values_of_lossy_vec(&self, name: &str) -> Vec<String>

Like values_of_lossy, but returns an empty vec if the flag is not present.

source

fn usize_of_nonzero(&self, name: &str) -> Result<Option<usize>, Box<dyn Error>>

Safely reads an arg value with the given name, and if it’s present, tries to parse it as a usize value.

If the number is zero, then it is considered absent and None is returned.

source

fn usize_of(&self, name: &str) -> Result<Option<usize>, Box<dyn Error>>

Safely reads an arg value with the given name, and if it’s present, tries to parse it as a usize value.

source

fn parse_human_readable_size( &self, arg_name: &str ) -> Result<Option<u64>, Box<dyn Error>>

Parses an argument of the form [0-9]+(KMG)?.

If the aforementioned format is not recognized, then this returns an error.

source§

impl ArgMatches

The following methods mostly dispatch to the underlying clap methods directly. Methods that would otherwise get a single value will fetch all values and return the last one. (Clap returns the first one.) We only define the ones we need.

source

fn is_present(&self, name: &str) -> bool

source

fn occurrences_of(&self, name: &str) -> u64

source

fn value_of_lossy(&self, name: &str) -> Option<String>

source

fn values_of_lossy(&self, name: &str) -> Option<Vec<String>>

source

fn value_of_os(&self, name: &str) -> Option<&OsStr>

source

fn values_of_os(&self, name: &str) -> Option<OsValues<'_>>

Trait Implementations§

source§

impl Clone for ArgMatches

source§

fn clone(&self) -> ArgMatches

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ArgMatches

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.