top_to_bottom/
top_to_bottom.rsuse bpaf::*;
use std::path::PathBuf;
#[allow(dead_code)]
#[derive(Debug, Clone)]
struct Out {
debug: bool,
verbose: usize,
speed: f64,
output: PathBuf,
nb_cars: u32,
files_to_process: Vec<PathBuf>,
}
fn main() {
let opt = (construct!(Out {
debug(),
verbose(),
speed(),
output(),
nb_cars(),
files_to_process()
}))
.to_options()
.run();
println!("{:#?}", opt);
}
fn debug() -> impl Parser<bool> {
short('d')
.long("debug")
.help("Activate debug mode")
.switch()
}
fn verbose() -> impl Parser<usize> {
short('v')
.long("verbose")
.help("Increase the verbosity\nYou can specify it up to 3 times\neither as -v -v -v or as -vvv")
.req_flag(())
.many()
.map(|xs| xs.len())
.guard(|&x| x <= 3, "It doesn't get any more verbose than this")
}
fn speed() -> impl Parser<f64> {
short('s')
.long("speed")
.help("Set speed")
.argument::<f64>("SPEED")
.fallback(42.0)
}
fn output() -> impl Parser<PathBuf> {
short('o')
.long("output")
.help("output file")
.argument::<PathBuf>("OUTPUT")
}
fn nb_cars() -> impl Parser<u32> {
short('n').long("nb-cars").argument::<u32>("N")
}
fn files_to_process() -> impl Parser<Vec<PathBuf>> {
short('f')
.long("file")
.help("File to process")
.argument::<PathBuf>("FILE")
.many()
}