pub struct Args { /* private fields */ }
Expand description
All currently present command line parameters, use it for unit tests and manual parsing
The easiest way to create Args
is by using it’s From
instance.
let parser = short('f')
.switch()
.to_options();
let value = parser
.run_inner(Args::from(&["-f"]))
.unwrap();
assert!(value);
Implementations§
source§impl<'a> Args
impl<'a> Args
sourcepub fn set_comp(self, rev: usize) -> Self
pub fn set_comp(self, rev: usize) -> Self
enable completions with custom output revision style
Panics
Contains some assertions which shouldn’t trigger in normal operation
Examples found in repository?
src/complete_run.rs (line 229)
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
pub(crate) fn args_with_complete(
os_name: OsString,
arguments: &[OsString],
complete_arguments: &[OsString],
) -> Args {
let path = PathBuf::from(os_name);
let path = path.file_name().expect("binary with no name?").to_str();
// not trying to run a completer - just make the arguments
if complete_arguments.is_empty() {
return Args::from(arguments);
}
let cargs = Args::from(complete_arguments);
match parse_comp_options().run_inner(cargs) {
Ok(comp) => {
let name = match path {
Some(path) => path,
None => panic!("app name is not utf8, giving up rendering completer"),
};
let rev = match comp {
CompOptions::Dump { style } => {
match style {
Style::Bash => dump_bash_completer(name),
Style::Zsh => dump_zsh_completer(name),
Style::Fish => dump_fish_completer(name),
Style::Elvish => dump_elvish_completer(name),
}
std::process::exit(0)
}
CompOptions::Complete { revision } => revision,
};
Args::from(arguments).set_comp(rev)
}
Err(err) => {
eprintln!("Can't parse bpaf complete options: {:?}", err);
std::process::exit(1);
}
}
}