Skip to main content

Cli

Struct Cli 

Source
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: bool

Don’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: bool

Invert the regex match: emit lines that do NOT match -e.

§with_filename: bool

Always 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: bool

With -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

Source

pub fn get_selector(&self) -> Option<String>

Get the selector from arguments (only valid when not using -e).

Source

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.

Source

pub fn validate(&self) -> Result<()>

Validate CLI arguments and check for conflicts.

Source

pub fn color_mode(&self) -> ColorMode

Get the color mode based on the –color flag and terminal detection.

Source§

impl Cli

Source

pub fn make_sink(&self) -> Result<Box<dyn Sink>>

Construct the output sink based on --output/--force flags.

Source

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.

Source

pub fn into_app_for_file_with_sink( &self, path: &Path, show_filename: bool, sink: Box<dyn Sink>, ) -> Result<App<Seek>>

Source

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.

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

Source§

fn group_id() -> Option<Id>

Report the ArgGroup::id for this set of arguments
Source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate Self via FromArgMatches::from_arg_matches_mut Read more
Source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate self via FromArgMatches::update_from_arg_matches_mut Read more
Source§

impl CommandFactory for Cli

Source§

fn command<'b>() -> Command

Build a Command that can instantiate Self. Read more
Source§

fn command_for_update<'b>() -> Command

Build a Command that can update self. Read more
Source§

impl Debug for Cli

Source§

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

Formats the value using the given formatter. Read more
Source§

impl FromArgMatches for Cli

Source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

impl Parser for Cli

Source§

fn parse() -> Self

Parse from std::env::args_os(), exit on error.
Source§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
Source§

fn parse_from<I, T>(itr: I) -> Self
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, exit on error.
Source§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
Source§

fn update_from<I, T>(&mut self, itr: I)
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, exit on error. Read more
Source§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.

Auto Trait Implementations§

§

impl Freeze for Cli

§

impl RefUnwindSafe for Cli

§

impl Send for Cli

§

impl Sync for Cli

§

impl Unpin for Cli

§

impl UnsafeUnpin for Cli

§

impl UnwindSafe for Cli

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.