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<'_>
impl Args<'_>
Sourcepub fn set_comp(self, rev: usize) -> Self
Available on crate feature autocomplete
only.
pub fn set_comp(self, rev: usize) -> Self
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");
Note to self: shell passes “” as a parameter in situations like foo --bar TAB
, bpaf
completion stubs adopt this conventions add pass it along. This is needed so completer can
tell the difference between --bar
being completed or an argument to it in the example
above.
Source§impl Args<'_>
impl Args<'_>
Sourcepub fn current_args() -> Self
pub fn current_args() -> Self
Get a list of command line arguments from OS
Trait Implementations§
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> 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
Mutably borrows from an owned value. Read more