ppvr/
args.rs

1use clap::Parser;
2use std::env;
3
4#[derive(Parser, Debug)]
5#[clap(author, version, about, long_about = None)]
6pub struct Args {
7    #[clap(help = "Read from a file instead of stdin", default_value = "")]
8    pub infile: String,
9    #[clap(
10        short = 'o',
11        long = "outfile",
12        takes_value = true,
13        help = "Write to stdout instead of stdout",
14        default_value = ""
15    )]
16    pub outfile: String,
17    #[clap(short = 's', long = "silent", help = "silent output")]
18    pub silent: bool,
19}
20
21impl Args {
22    pub fn get_args() -> Self {
23        let args = Args::parse();
24        let silent = if args.silent {
25            true
26        } else {
27            !env::var("PPVR_SILENT").unwrap_or_default().is_empty()
28        };
29
30        Self {
31            infile: args.infile,
32            outfile: args.outfile,
33            silent,
34        }
35    }
36}