use camino::Utf8PathBuf; use clap::Parser; #[derive(Debug, Parser)] pub struct Args { #[clap(short, long)] pub expression: String, #[clap(short, long, default_value_t = Utf8PathBuf::from("-"))] input: Utf8PathBuf, #[clap(short, long, group = "delimiters")] lines: bool, #[clap(short, long, group = "delimiters", default_value_t = true)] words: bool, } pub enum InputDelimiter { Lines, Words, } pub enum Input { Stdin, FilePath(Utf8PathBuf), } impl Args { pub fn delimiter(&self) -> InputDelimiter { if self.lines { return InputDelimiter::Lines; } if self.words { return InputDelimiter::Words; } unreachable!("Either lines or words has to be true") } pub fn input(&self) -> Input { if self.input == "-" { Input::Stdin } else { Input::FilePath(self.input.clone()) } } }