1use clap::{App, Arg};
2use std::env;
3
4pub struct Args {
5 pub infile: String,
6 pub outfile: String,
7 pub silent: bool,
8}
9
10impl Args {
11 pub fn parse() -> Self {
12 let matches = App::new("flo-pv")
13 .arg(Arg::with_name("infile").help("Read from a file instead of stdin"))
14 .arg(
15 Arg::with_name("outfile")
16 .short("o")
17 .long("outfile")
18 .takes_value(true)
19 .help("Write output to a file instead of stdout"),
20 )
21 .arg(Arg::with_name("silent").short("s").long("silent"))
22 .get_matches();
23
24 let infile = matches.value_of("infile").unwrap_or_default().to_string();
25 let outfile = matches.value_of("outfile").unwrap_or_default().to_string();
26 let silent = if matches.is_present("silent") {
27 true
28 } else {
29 !env::var("PV_SILENT").unwrap_or_default().is_empty()
30 };
31
32 Self {
33 infile,
34 outfile,
35 silent,
36 }
37 }
38}