summaryrefslogtreecommitdiff
path: root/cli/src/main.rs
diff options
context:
space:
mode:
authorfigsoda <figsoda@pm.me>2023-04-06 14:14:01 -0400
committerGitHub <noreply@github.com>2023-04-06 20:14:01 +0200
commit1c324765e92c23826dff4f37d3b01761a3ac6ef4 (patch)
tree1c84390a6ff58545374b7cbfa3c74f82af306558 /cli/src/main.rs
parent75461675c4e57675174d98060124c9e13beaf7e4 (diff)
Add shell completions and man pages (#582)
Diffstat (limited to 'cli/src/main.rs')
-rw-r--r--cli/src/main.rs63
1 files changed, 7 insertions, 56 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs
index d0dcc2bd..1190232d 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -1,3 +1,5 @@
+mod args;
+
use std::cell::{RefCell, RefMut};
use std::collections::HashMap;
use std::fs::{self, File};
@@ -6,7 +8,7 @@ use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process;
-use clap::{ArgAction, Parser, Subcommand};
+use clap::Parser;
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::term::{self, termcolor};
use comemo::Prehashed;
@@ -25,64 +27,13 @@ use typst::util::{Buffer, PathExt};
use typst::World;
use walkdir::WalkDir;
+use crate::args::{CliArguments, Command, CompileCommand};
+
type CodespanResult<T> = Result<T, CodespanError>;
type CodespanError = codespan_reporting::files::Error;
-const TYPST_VERSION: &str = env!("TYPST_VERSION");
-
-/// typst creates PDF files from .typ files
-#[derive(Debug, Clone, Parser)]
-#[clap(name = "typst", version = TYPST_VERSION, author)]
-pub struct CliArguments {
- /// Add additional directories to search for fonts
- #[clap(long = "font-path", value_name = "DIR", action = ArgAction::Append)]
- font_paths: Vec<PathBuf>,
-
- /// Configure the root for absolute paths
- #[clap(long = "root", value_name = "DIR")]
- root: Option<PathBuf>,
-
- /// The typst command to run
- #[command(subcommand)]
- command: Command,
-}
-
-/// What to do.
-#[derive(Debug, Clone, Subcommand)]
-#[command()]
-enum Command {
- /// Compiles the input file into a PDF file
- #[command(visible_alias = "c")]
- Compile(CompileCommand),
-
- /// Watches the input file and recompiles on changes
- #[command(visible_alias = "w")]
- Watch(CompileCommand),
-
- /// List all discovered fonts in system and custom font paths
- Fonts(FontsCommand),
-}
-
-/// Compiles the input file into a PDF file
-#[derive(Debug, Clone, Parser)]
-pub struct CompileCommand {
- /// Path to input Typst file
- input: PathBuf,
-
- /// Path to output PDF file
- output: Option<PathBuf>,
-
- /// Opens the output file after compilation using the default PDF viewer
- #[arg(long = "open")]
- open: Option<Option<String>>,
-}
-
-/// List all discovered fonts in system and custom font paths
-#[derive(Debug, Clone, Parser)]
-pub struct FontsCommand {
- /// Also list style variants of each font family
- #[arg(long)]
- variants: bool,
+pub fn typst_version() -> &'static str {
+ env!("TYPST_VERSION")
}
/// A summary of the input arguments relevant to compilation.