1use std::{path::PathBuf, str::FromStr};
2
3#[derive(Clone, Debug, clap::Parser)]
4#[command(version)]
5pub struct Args {
6 pub font_path: PathBuf,
7 #[arg(short, long)]
8 pub out: Option<PathBuf>,
10 #[arg(short, long, default_value_t)]
12 pub table: Table,
13 #[arg(short, long)]
15 pub index: Option<u32>,
16}
17
18#[derive(Clone, Debug, Default)]
20pub enum Table {
21 #[default]
22 All,
23 Gpos,
24 Gsub,
25 Gdef,
26}
27
28impl std::fmt::Display for Table {
29 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
30 match self {
31 Table::All => f.write_str("all"),
32 Table::Gpos => f.write_str("gpos"),
33 Table::Gsub => f.write_str("gsub"),
34 Table::Gdef => f.write_str("gdef"),
35 }
36 }
37}
38
39impl FromStr for Table {
40 type Err = &'static str;
41
42 fn from_str(s: &str) -> Result<Self, Self::Err> {
43 static ERR_MSG: &str = "expected one of 'gsub', 'gpos', 'gdef', 'all'";
44 match s.to_ascii_lowercase().trim() {
45 "gpos" => Ok(Self::Gpos),
46 "gsub" => Ok(Self::Gsub),
47 "gdef" => Ok(Self::Gdef),
48 "all" => Ok(Self::All),
49 _ => Err(ERR_MSG),
50 }
51 }
52}