Add initial parsing
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
12327bb44c
commit
87db209786
6 changed files with 244 additions and 2 deletions
49
src/cli.rs
Normal file
49
src/cli.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue