Add initial parsing

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2025-06-29 12:07:07 +02:00
parent 12327bb44c
commit 87db209786
6 changed files with 244 additions and 2 deletions

49
src/cli.rs Normal file
View 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())
}
}
}