diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-21 01:10:56 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-21 01:48:40 +0100 |
| commit | b48b0d650cc045fb309819d34928478c05640bf9 (patch) | |
| tree | f1cf0637371f31a61fdc3de1a8290e83322d972e /cli | |
| parent | c8b0be21f50b881756fcb61c6b72a96081264e3e (diff) | |
Release action
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/build.rs | 9 | ||||
| -rw-r--r-- | cli/src/main.rs | 13 |
2 files changed, 21 insertions, 1 deletions
diff --git a/cli/build.rs b/cli/build.rs new file mode 100644 index 00000000..f7b70e7f --- /dev/null +++ b/cli/build.rs @@ -0,0 +1,9 @@ +use std::error::Error; +use std::process::Command; + +fn main() -> Result<(), Box<dyn Error>> { + let output = Command::new("git").args(&["rev-parse", "HEAD"]).output()?; + let hash = std::str::from_utf8(&output.stdout)?; + println!("cargo:rustc-env=TYPST_HASH={}", &hash[..8]); + Ok(()) +} diff --git a/cli/src/main.rs b/cli/src/main.rs index b7cac1ee..40d1a780 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -55,6 +55,7 @@ ARGS: OPTIONS: -h, --help Print this help + -V, --version Print the CLI's version -w, --watch Watch the inputs and recompile on changes --root <dir> Configure the root for absolute paths @@ -94,6 +95,10 @@ fn main() { /// Parse command line arguments. fn parse_args() -> StrResult<Command> { let mut args = Arguments::from_env(); + if args.contains(["-V", "--version"]) { + print_version(); + } + let help = args.contains(["-h", "--help"]); let command = if args.contains("--fonts") { @@ -144,11 +149,17 @@ fn parse_input_output(args: &mut Arguments, ext: &str) -> StrResult<(PathBuf, Pa } /// Print a help string and quit. -fn print_help(help: &'static str) { +fn print_help(help: &'static str) -> ! { print!("{help}"); std::process::exit(0); } +/// Print the version hash and quit. +fn print_version() -> ! { + println!("typst {}", env!("TYPST_HASH")); + std::process::exit(0); +} + /// Print an application-level error (independent from a source file). fn print_error(msg: &str) -> io::Result<()> { let mut w = StandardStream::stderr(ColorChoice::Always); |
