diff --git a/src/cli.rs b/src/cli.rs index 0b2ea81..c2ba11f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,3 +1,4 @@ +use crate::display::format_dentition; use crate::lib::NotationKind; use crate::lib::Tooth; use clap::{Parser, Subcommand, ValueEnum}; @@ -20,6 +21,12 @@ enum Action { #[clap(value_parser)] value: String, }, + Display { + #[clap(value_enum, short = 'n', long)] + notation: NotationKindArg, + #[clap(takes_value = false, short = 'p', long)] + primary: bool, + }, } #[derive(Parser, Debug)] struct Args { @@ -34,17 +41,23 @@ fn convert_kind(kind_arg: &NotationKindArg) -> NotationKind { 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 tooth_result = Tooth::from(value, &convert_kind(from)); + let output_string = match tooth_result { + Ok(tooth) => tooth.to(&convert_kind(to)), Err(err) => err, - Ok(ok) => ok, }; + println!("{}", output_string); } + Action::Display { notation, primary } => { + println!("{}", format_dentition(!primary, &convert_kind(notation))) + } }; } diff --git a/src/lib.rs b/src/lib.rs index 330fce4..801d45b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -230,18 +230,27 @@ impl Tooth { quadrant.to_owned() + &number } - pub fn convert(from: &NotationKind, to: &NotationKind, value: &str) -> Result { - let tooth_result = match from { + pub fn from(value: &str, from: &NotationKind) -> Result { + match from { NotationKind::Iso => Tooth::from_iso(value), NotationKind::Uns => Tooth::from_uns(value), NotationKind::Alphanumeric => Tooth::from_alphanumeric(value), - }; + } + } + pub fn to(&self, to: &NotationKind) -> String { + match to { + NotationKind::Iso => self.to_iso(), + NotationKind::Uns => self.to_uns(), + NotationKind::Alphanumeric => self.to_alphanumeric(), + } + } + + #[deprecated(since = "1.0.0", note = "Use 'to' and 'from' directly")] + pub fn convert(from: &NotationKind, to: &NotationKind, value: &str) -> Result { + let tooth_result = Tooth::from(value, from); + match tooth_result { - Ok(tooth) => match to { - NotationKind::Iso => Ok(tooth.to_iso()), - NotationKind::Uns => Ok(tooth.to_uns()), - NotationKind::Alphanumeric => Ok(tooth.to_alphanumeric()), - }, + Ok(tooth) => Ok(tooth.to(to)), Err(err) => Err(err), } }