From 89cecb188d3905ecf98f2a6be93cbd7cf6bf8a64 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 15 Oct 2024 13:55:55 +0200 Subject: Greet users who run `typst` for the first time (#5210) --- crates/typst-cli/src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'crates/typst-cli/src/main.rs') diff --git a/crates/typst-cli/src/main.rs b/crates/typst-cli/src/main.rs index 283d17e2..b14e687e 100644 --- a/crates/typst-cli/src/main.rs +++ b/crates/typst-cli/src/main.rs @@ -2,6 +2,7 @@ mod args; mod compile; mod download; mod fonts; +mod greet; mod init; mod package; mod query; @@ -16,6 +17,7 @@ use std::cell::Cell; use std::io::{self, Write}; use std::process::ExitCode; +use clap::error::ErrorKind; use clap::Parser; use codespan_reporting::term; use codespan_reporting::term::termcolor::WriteColor; @@ -30,8 +32,15 @@ thread_local! { static EXIT: Cell = const { Cell::new(ExitCode::SUCCESS) }; } -/// The parsed commandline arguments. -static ARGS: Lazy = Lazy::new(CliArguments::parse); +/// The parsed command line arguments. +static ARGS: Lazy = Lazy::new(|| { + CliArguments::try_parse().unwrap_or_else(|error| { + if error.kind() == ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand { + crate::greet::greet(); + } + error.exit(); + }) +}); /// Entry point. fn main() -> ExitCode { -- cgit v1.2.3