diff options
Diffstat (limited to 'cli/src/args.rs')
| -rw-r--r-- | cli/src/args.rs | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/cli/src/args.rs b/cli/src/args.rs index 6b9f3df8..7fdb041b 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -11,41 +11,12 @@ pub struct CliArguments { #[command(subcommand)] pub command: Command, - /// Configure the project root - #[clap(long = "root", env = "TYPST_ROOT", value_name = "DIR")] - pub root: Option<PathBuf>, - - /// Add additional directories to search for fonts - #[clap( - long = "font-path", - env = "TYPST_FONT_PATHS", - value_name = "DIR", - action = ArgAction::Append, - )] - pub font_paths: Vec<PathBuf>, - /// Sets the level of logging verbosity: /// -v = warning & error, -vv = info, -vvv = debug, -vvvv = trace #[clap(short, long, action = ArgAction::Count)] pub verbosity: u8, } -/// Which format to use for diagnostics. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, ValueEnum)] -pub enum DiagnosticFormat { - Human, - Short, -} - -impl Display for DiagnosticFormat { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - self.to_possible_value() - .expect("no values are skipped") - .get_name() - .fmt(f) - } -} - /// What to do. #[derive(Debug, Clone, Subcommand)] #[command()] @@ -62,22 +33,6 @@ pub enum Command { Fonts(FontsCommand), } -impl Command { - /// Returns the compile command if this is a compile or watch command. - pub fn as_compile(&self) -> Option<&CompileCommand> { - match self { - Command::Compile(cmd) => Some(cmd), - Command::Watch(cmd) => Some(cmd), - Command::Fonts(_) => None, - } - } - - /// Returns whether this is a watch command. - pub fn is_watch(&self) -> bool { - matches!(self, Command::Watch(_)) - } -} - /// Compiles the input file into a PDF file #[derive(Debug, Clone, Parser)] pub struct CompileCommand { @@ -87,13 +42,26 @@ pub struct CompileCommand { /// Path to output PDF file or PNG file(s) pub output: Option<PathBuf>, + /// Configure the project root + #[clap(long = "root", env = "TYPST_ROOT", value_name = "DIR")] + pub root: Option<PathBuf>, + + /// Add additional directories to search for fonts + #[clap( + long = "font-path", + env = "TYPST_FONT_PATHS", + value_name = "DIR", + action = ArgAction::Append, + )] + pub font_paths: Vec<PathBuf>, + /// Opens the output file after compilation using the default PDF viewer #[arg(long = "open")] pub open: Option<Option<String>>, /// The PPI to use if exported as PNG - #[arg(long = "ppi")] - pub ppi: Option<f32>, + #[arg(long = "ppi", default_value_t = 144.0)] + pub ppi: f32, /// In which format to emit diagnostics #[clap( @@ -108,10 +76,44 @@ pub struct CompileCommand { pub flamegraph: Option<Option<PathBuf>>, } +impl CompileCommand { + /// The output path. + pub fn output(&self) -> PathBuf { + self.output + .clone() + .unwrap_or_else(|| self.input.with_extension("pdf")) + } +} + /// List all discovered fonts in system and custom font paths #[derive(Debug, Clone, Parser)] pub struct FontsCommand { + /// Add additional directories to search for fonts + #[clap( + long = "font-path", + env = "TYPST_FONT_PATHS", + value_name = "DIR", + action = ArgAction::Append, + )] + pub font_paths: Vec<PathBuf>, + /// Also list style variants of each font family #[arg(long)] pub variants: bool, } + +/// Which format to use for diagnostics. +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, ValueEnum)] +pub enum DiagnosticFormat { + Human, + Short, +} + +impl Display for DiagnosticFormat { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.to_possible_value() + .expect("no values are skipped") + .get_name() + .fmt(f) + } +} |
