Struct bpaf::Args

source ·
pub struct Args<'a> { /* private fields */ }
Expand description

All currently present command line parameters with some extra metainfo

Use it for unit tests and manual parsing. For production use you would want to replace the program name with set_name, but for tests passing a slice of strings to run_inner is usually more convenient.

The easiest way to create Args is by using its From instance.

let parser = short('f')
    .switch()
    .to_options();
let value = parser
    .run_inner(Args::from(&["-f"]))
    .unwrap();
assert!(value);

// this also works
let value = parser.run_inner(&["-f"])
    .unwrap();
assert!(value);

Implementations§

source§

impl Args<'_>

source

pub fn set_comp(self, rev: usize) -> Self

Available on crate feature autocomplete only.

Enable completions with custom output revision style

Use revision 0 if you want to test completion mechanism

let parser = short('f').switch().to_options();
// ask bpaf to produce more input from "-", for
// suggesting new items use "" at the end
let r = parser.run_inner(Args::from(&["-"])
    .set_comp(0))
    .unwrap_err()
    .unwrap_stdout();
assert_eq!(r, "-f");
source

pub fn set_name(self, name: &str) -> Self

Add an application name for args created from custom input

let parser = short('f').switch().to_options();
let r = parser
    .run_inner(Args::from(&["--help"]).set_name("my_app"))
    .unwrap_err()
    .unwrap_stdout();
source§

impl Args<'_>

source

pub fn current_args() -> Self

Get a list of command line arguments from OS

Trait Implementations§

source§

impl<'a> From<&'a [&'a OsStr]> for Args<'a>

source§

fn from(value: &'a [&'a OsStr]) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a [&'a str]> for Args<'a>

source§

fn from(value: &'a [&'a str]) -> Self

Converts to this type from the input type.
source§

impl<const N: usize> From<&'static [&'static str; N]> for Args<'_>

source§

fn from(value: &'static [&'static str; N]) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a [OsString]> for Args<'a>

source§

fn from(value: &'a [OsString]) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a [String]> for Args<'a>

source§

fn from(value: &'a [String]) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for Args<'a>

§

impl<'a> !RefUnwindSafe for Args<'a>

§

impl<'a> !Send for Args<'a>

§

impl<'a> !Sync for Args<'a>

§

impl<'a> Unpin for Args<'a>

§

impl<'a> !UnwindSafe for Args<'a>

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

§

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

§

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.