> module
std::cli
argument parsing and interactive prompts
std::cli parses the program's command-line arguments with pico-args, draws tables, and asks questions on the terminal with inquire. The arguments are the ones after the script's path (see std::argv).
> functions
Opens an editor ($EDITOR, else $VISUAL, else nano or notepad) and returns the text saved in it.
Asks the user to pick any number of options.
Parses all the arguments at once. Each spec is [long, kind] or [long, short, kind], such as ["--out", "-o", "option"]. kind is "flag" (a bool), "option" (an Option<str>) or "value" (a required str). The record has a field per spec, named after the long form without its dashes and with - turned into _ (--dry-run gives dry_run), and an empty rest list. Returns Err naming any arguments left over. A missing required value or an option without its value is a runtime error.
Asks the user to pick one of options, which must not be empty.
> types
Each method consumes what it finds, so later calls don't see it. A flag is named by one spelling, such as "--verbose", or by two, a short and a long one in either order, as in args.option("--output", "-o"). A name that isn't -x or --name is a runtime error.
Whether the flag is present anywhere among the arguments.
Checks that nothing is left: Err(cli::Error::Unexpected(names)) if something is.
The next remaining argument, whatever it is, or None if none are left. Call it after taking the flags and options.
The value after the option, as in --output out.txt, or None if it isn't given. The option without a value is a runtime error.
The first remaining argument, if it doesn't start with -; otherwise None.
> prompts
Each prompt waits for the user. If the user cancels (Esc or Ctrl-C) or stdin isn't a terminal, it is a runtime error.
> errors
cli::Error is a matchable enum: Arg(str) for a missing or unreadable argument, and Unexpected(str) for arguments left over at finish.
> examples
use std::cli;
use std::io;
fn main() -> Result<()> {
let args = cli::args();
let verbose = args.contains("--verbose");
let output = args.option("--output");
let input = args.free()?;
args.finish()?;
match input {
Some(file) => io::println("processing: {}", file),
None => io::println("no input file given"),
}
Ok(())
}