summaryrefslogtreecommitdiff
path: root/cli/src/args.rs
diff options
context:
space:
mode:
authorerikwastaken <46598911+erikwastaken@users.noreply.github.com>2023-05-23 12:34:12 +0200
committerGitHub <noreply@github.com>2023-05-23 12:34:12 +0200
commit2cbeeae5da0b5c3d8c50d1dd522f900a1f86b8fa (patch)
treeb94506a7fe919e511077e602c87862dc1ebd12f4 /cli/src/args.rs
parent5400570efa13d24519e321474f41ebda5cc4cbc7 (diff)
CLI option for emitting diagnostics in a unix-style short format (#1176)
Diffstat (limited to 'cli/src/args.rs')
-rw-r--r--cli/src/args.rs43
1 files changed, 34 insertions, 9 deletions
diff --git a/cli/src/args.rs b/cli/src/args.rs
index fbd5ec2d..d794347c 100644
--- a/cli/src/args.rs
+++ b/cli/src/args.rs
@@ -1,11 +1,16 @@
+use std::fmt::{self, Display, Formatter};
use std::path::PathBuf;
-use clap::{ArgAction, Parser, Subcommand};
+use clap::{ArgAction, Parser, Subcommand, ValueEnum};
/// typst creates PDF files from .typ files
#[derive(Debug, Clone, Parser)]
#[clap(name = "typst", version = crate::typst_version(), author)]
pub struct CliArguments {
+ /// The typst command to run
+ #[command(subcommand)]
+ pub command: Command,
+
/// 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>,
@@ -14,16 +19,28 @@ pub struct CliArguments {
#[clap(long = "root", env = "TYPST_ROOT", value_name = "DIR")]
pub root: Option<PathBuf>,
- /// The typst command to run
- #[command(subcommand)]
- pub command: Command,
-
/// 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()]
@@ -69,13 +86,21 @@ pub struct CompileCommand {
#[arg(long = "open")]
pub open: Option<Option<String>>,
- /// Produces a flamegraph of the compilation process
- #[arg(long = "flamegraph", value_name = "OUTPUT_SVG")]
- pub flamegraph: Option<Option<PathBuf>>,
-
/// The PPI to use if exported as PNG
#[arg(long = "ppi")]
pub ppi: Option<f32>,
+
+ /// In which format to emit diagnostics
+ #[clap(
+ long,
+ default_value_t = DiagnosticFormat::Human,
+ value_parser = clap::value_parser!(DiagnosticFormat)
+ )]
+ pub diagnostic_format: DiagnosticFormat,
+
+ /// Produces a flamegraph of the compilation process
+ #[arg(long = "flamegraph", value_name = "OUTPUT_SVG")]
+ pub flamegraph: Option<Option<PathBuf>>,
}
/// List all discovered fonts in system and custom font paths