feat: Add convert cli
This commit is contained in:
parent
51f2641804
commit
336a7c651b
50
src/cli.rs
Normal file
50
src/cli.rs
Normal file
@ -0,0 +1,50 @@
|
||||
use crate::lib::NotationKind;
|
||||
use crate::lib::Tooth;
|
||||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
|
||||
#[derive(Copy, Clone, Debug, ValueEnum)]
|
||||
enum NotationKindArg {
|
||||
Iso,
|
||||
Uns,
|
||||
Alphanumeric,
|
||||
}
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum Action {
|
||||
Convert {
|
||||
#[clap(value_enum, short = 'f', long)]
|
||||
from: NotationKindArg,
|
||||
|
||||
#[clap(value_enum, short = 't', long)]
|
||||
to: NotationKindArg,
|
||||
|
||||
#[clap(value_parser)]
|
||||
value: String,
|
||||
},
|
||||
}
|
||||
#[derive(Parser, Debug)]
|
||||
struct Args {
|
||||
#[clap(subcommand)]
|
||||
action: Action,
|
||||
}
|
||||
|
||||
fn convert_kind(kind_arg: &NotationKindArg) -> NotationKind {
|
||||
match kind_arg {
|
||||
NotationKindArg::Iso => NotationKind::Iso,
|
||||
NotationKindArg::Uns => NotationKind::Uns,
|
||||
NotationKindArg::Alphanumeric => NotationKind::Alphanumeric,
|
||||
}
|
||||
}
|
||||
pub fn run_cli() {
|
||||
let args = Args::parse();
|
||||
|
||||
match &args.action {
|
||||
Action::Convert { from, to, value } => {
|
||||
let tooth_result = Tooth::convert(&convert_kind(from), &convert_kind(&to), value);
|
||||
let output_string = match tooth_result {
|
||||
Err(err) => err,
|
||||
Ok(ok) => ok,
|
||||
};
|
||||
println!("{}", output_string);
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user