pipeviewer/
args.rs

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("pipeviewer")
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        let infile = matches.value_of("infile").unwrap_or_default().to_string();
24        let outfile = matches.value_of("outfile").unwrap_or_default().to_string();
25        let silent = if matches.is_present("silent") {
26            true
27        } else {
28            !env::var("PV_SILENT").unwrap_or_default().is_empty()
29        };
30        Self {
31            infile,
32            outfile,
33            silent,
34        }
35    }
36}