diff options
| author | Matt Fellenz <matt@felle.nz> | 2023-08-23 13:44:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-23 22:44:03 +0200 |
| commit | ff5dc9191e15d032c8e87065c68c232c650419a8 (patch) | |
| tree | 5a9cbbbe3070f101ed3d118ca709d1bc6370402b /crates/typst-cli/src/args.rs | |
| parent | 3fcb5ea73cbae20500f4695685df4caf0071d45a (diff) | |
Add format arg to CLI (#1985)
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) + } +} |
