Skip to content

Instantly share code, notes, and snippets.

@hype08
Created April 30, 2021 21:35
Show Gist options
  • Save hype08/e710a1c02ed717f861632b8a1d65888c to your computer and use it in GitHub Desktop.
Save hype08/e710a1c02ed717f861632b8a1d65888c to your computer and use it in GitHub Desktop.
Parsing the command line – the structopt crate
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
struct Opt {
/// Activate verbose mode
#[structopt(short = "v", long = "verbose")]
verbose: bool,
/// File to generate
#[structopt(short = "r", long = "result", parse(from_os_str))]
result_file: PathBuf,
/// Files to process
#[structopt(name = "FILE", parse(from_os_str))]
files: Vec<PathBuf>,
}
fn main() {
println!("{:#?}", Opt::from_args());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment