diff options
Diffstat (limited to 'crates/typst-cli/src/args.rs')
| -rw-r--r-- | crates/typst-cli/src/args.rs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/crates/typst-cli/src/args.rs b/crates/typst-cli/src/args.rs index 6bc58443..2696a031 100644 --- a/crates/typst-cli/src/args.rs +++ b/crates/typst-cli/src/args.rs @@ -46,6 +46,10 @@ pub struct CompileCommand { /// Path to output file (PDF, PNG, or SVG) pub output: Option<PathBuf>, + /// The format of the output file, inferred from the extension by default + #[arg(long = "format", short = 'f')] + pub format: Option<OutputFormat>, + /// Opens the output file using the default viewer after compilation #[arg(long = "open")] pub open: Option<Option<String>>, @@ -59,15 +63,6 @@ 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.common.input.with_extension("pdf")) - } -} - /// Processes an input file to extract provided metadata #[derive(Debug, Clone, Parser)] pub struct QueryCommand { @@ -158,3 +153,20 @@ impl Display for DiagnosticFormat { .fmt(f) } } + +/// Which format to use for the generated output file. +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, ValueEnum)] +pub enum OutputFormat { + Pdf, + Png, + Svg, +} + +impl Display for OutputFormat { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.to_possible_value() + .expect("no values are skipped") + .get_name() + .fmt(f) + } +} |
