pub struct Cli {
pub context: Option<usize>,
pub char_context: Option<usize>,
pub no_line_numbers: bool,
pub regex: Option<String>,
pub invert: bool,
pub with_filename: bool,
pub color: Option<String>,
pub output: Option<String>,
pub force: bool,
pub args: Vec<String>,
}Expand description
sel — Select slices from text files by line numbers, ranges, positions, or regex.
Fields§
§context: Option<usize>Show N lines of context before and after matches
char_context: Option<usize>Show N characters of context around position
Only works with positional selectors (L:C) or with -e.
no_line_numbers: boolDon’t output line numbers
Filenames are still shown when processing multiple files.
regex: Option<String>Regular expression pattern (PCRE-like syntax)
When using -e, the selector argument is ignored. Multiple files can be specified with -e.
invert: boolInvert the regex match: emit lines that do NOT match -e.
with_filename: boolAlways print filename prefix
By default, filename is only shown when processing multiple files.
color: Option<String>Color output [auto, always, never]
Default is ‘auto’ (enabled when stdout is a terminal).
output: Option<String>Write output to FILE instead of stdout. Use - for stdout explicitly.
force: boolWith -o, overwrite an existing file.
args: Vec<String>Selector and/or file(s)
The first positional argument can be:
- A selector (line number, range, position) if it matches selector syntax
- A filename otherwise
When using -e, all positional arguments are treated as files.
Implementations§
Source§impl Cli
impl Cli
Sourcepub fn get_selector(&self) -> Option<String>
pub fn get_selector(&self) -> Option<String>
Get the selector from arguments (only valid when not using -e).
Sourcepub fn get_files(&self) -> Vec<PathBuf>
pub fn get_files(&self) -> Vec<PathBuf>
Get the list of input files.
Returns at least one entry — falls back to - (stdin) when no
explicit files are provided.
Sourcepub fn color_mode(&self) -> ColorMode
pub fn color_mode(&self) -> ColorMode
Get the color mode based on the –color flag and terminal detection.
Source§impl Cli
impl Cli
Sourcepub fn make_sink(&self) -> Result<Box<dyn Sink>>
pub fn make_sink(&self) -> Result<Box<dyn Sink>>
Construct the output sink based on --output/--force flags.
Sourcepub fn into_app_for_file(
&self,
path: &Path,
show_filename: bool,
) -> Result<App<Seek>>
pub fn into_app_for_file( &self, path: &Path, show_filename: bool, ) -> Result<App<Seek>>
Build a ready-to-run App for a single file.
Callers iterate over get_files() and build one App per file.
pub fn into_app_for_file_with_sink( &self, path: &Path, show_filename: bool, sink: Box<dyn Sink>, ) -> Result<App<Seek>>
Sourcepub fn into_app_for_stdin(&self, show_filename: bool) -> Result<App<NonSeek>>
pub fn into_app_for_stdin(&self, show_filename: bool) -> Result<App<NonSeek>>
Build a ready-to-run App for stdin input.
Returns PositionalWithStdin when paired with a positional selector
(line:column), which requires a seekable source.
pub fn into_app_for_stdin_with_sink( &self, show_filename: bool, sink: Box<dyn Sink>, ) -> Result<App<NonSeek>>
Trait Implementations§
Source§impl Args for Cli
impl Args for Cli
Source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Command so it can instantiate self via
FromArgMatches::update_from_arg_matches_mut Read moreSource§impl CommandFactory for Cli
impl CommandFactory for Cli
Source§impl FromArgMatches for Cli
impl FromArgMatches for Cli
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches to self.