pub struct ContextArgs {
pub context: Option<ContextMode>,
pub after_context: Option<usize>,
pub before_context: Option<usize>,
}Expand description
Shared context arguments for commands that retrieve content.
This group provides grep-style context line options for commands that return content with surrounding lines (search, get, find, etc.).
§Usage
Flatten into command structs:
#[derive(Args)]
struct GetArgs {
#[command(flatten)]
context: ContextArgs,
// ... other args
}Then resolve to a ContextMode:
let mode = args.context.resolve();Fields§
§context: Option<ContextMode>Lines of context before and after each match (grep-style).
Use a number for symmetric context, or “all” for full section.
Examples: -C 5 # 5 lines before and after –context 10 # 10 lines before and after –context all # Full section
after_context: Option<usize>Lines of context after each match.
Can be combined with -B for asymmetric context.
Examples: -A 5 # 5 lines after match –after-context 3 # 3 lines after match
before_context: Option<usize>Lines of context before each match.
Can be combined with -A for asymmetric context.
Examples: -B 5 # 5 lines before match –before-context 3 # 3 lines before match
Implementations§
Source§impl ContextArgs
impl ContextArgs
Sourcepub fn resolve(&self) -> Option<ContextMode>
pub fn resolve(&self) -> Option<ContextMode>
Resolve the context arguments into a single ContextMode.
Implements grep-style merging logic:
-Cprovides symmetric context-Aand-Bcan be combined for asymmetric context- If multiple flags are provided, takes maximum value for each direction
Sourcepub const fn has_context(&self) -> bool
pub const fn has_context(&self) -> bool
Check if any context is requested.
Trait Implementations§
Source§impl Args for ContextArgs
impl Args for ContextArgs
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 Clone for ContextArgs
impl Clone for ContextArgs
Source§fn clone(&self) -> ContextArgs
fn clone(&self) -> ContextArgs
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContextArgs
impl Debug for ContextArgs
Source§impl Default for ContextArgs
impl Default for ContextArgs
Source§fn default() -> ContextArgs
fn default() -> ContextArgs
Source§impl FromArgMatches for ContextArgs
impl FromArgMatches for ContextArgs
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.Source§impl PartialEq for ContextArgs
impl PartialEq for ContextArgs
impl Eq for ContextArgs
impl StructuralPartialEq for ContextArgs
Auto Trait Implementations§
impl Freeze for ContextArgs
impl RefUnwindSafe for ContextArgs
impl Send for ContextArgs
impl Sync for ContextArgs
impl Unpin for ContextArgs
impl UnwindSafe for ContextArgs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more