Repository: typst/typst
File: crates/typst-cli/src/args.rs (Rust)

Code before:
    /// Adds additional directories to search for fonts
    #[clap(
        long = "font-path",
        env = "TYPST_FONT_PATHS",
        value_name = "DIR",
        value_delimiter = ENV_PATH_SEP,
    )]
    pub font_paths: Vec<PathBuf>,

    /// The format to emit diagnostics in
    #[clap(
        long,
        default_value_t = DiagnosticFormat::Human,
        value_parser = clap::value_parser!(DiagnosticFormat)
    )]
    pub diagnostic_format: DiagnosticFormat,
}

/// An input path that is either stdin or a real path.
#[derive(Clone, Debug)]
pub enum InputPath {
    /// stdin, represented by `-`
    Stdin,
    /// A non-empty path
    Path(PathBuf),
}

/// The clap value parser used by `SharedArgs.input`
fn input_path_value_parser(value: &str) -> Result<InputPath, clap::error::Error> {
    if value.is_empty() {
        Err(clap::Error::new(clap::error::ErrorKind::InvalidValue))
    } else if value == "-" {
        Ok(InputPath::Stdin)
    } else {
        Ok(InputPath::Path(value.into()))
    }
}

/// Parses key/value pairs split by the first equal sign.
///
/// This function will return an error if the argument contains no equals sign
/// or contains the key (before the equals sign) is empty.
fn parse_input_pair(raw: &str) -> Result<(String, String), String> {
    let (key, val) = raw
        .split_once('=')
        .ok_or("input must be a key and a value separated by an equal sign")?;
    let key = key.trim().to_owned();
    if key.is_empty() {
        return Err("the key was missing or empty".to_owned());
    }
    let val = val.trim().to_owned();

Review comment (bug):
```suggestion
/// An input path that is either stdin or a real path.
#[derive(Debug, Clone)]
pub enum InputPath {
    /// Stdin, represented by `-`.
    Stdin,
    /// A non-empty path.
    Path(PathBuf),
}
```
would the name `Input` perhaps be more fitting than `InputPath`?

Code after:
    /// Adds additional directories to search for fonts
    #[clap(
        long = "font-path",
        env = "TYPST_FONT_PATHS",
        value_name = "DIR",
        value_delimiter = ENV_PATH_SEP,
    )]
    pub font_paths: Vec<PathBuf>,

    /// The format to emit diagnostics in
    #[clap(
        long,
        default_value_t = DiagnosticFormat::Human,
        value_parser = clap::value_parser!(DiagnosticFormat)
    )]
    pub diagnostic_format: DiagnosticFormat,
}

/// An input that is either stdin or a real path.
#[derive(Debug, Clone)]
pub enum Input {
    /// Stdin, represented by `-`.
    Stdin,
    /// A non-empty path.
    Path(PathBuf),
}

/// The clap value parser used by `SharedArgs.input`
fn input_value_parser(value: &str) -> Result<Input, clap::error::Error> {
    if value.is_empty() {
        Err(clap::Error::new(clap::error::ErrorKind::InvalidValue))
    } else if value == "-" {
        Ok(Input::Stdin)
    } else {
        Ok(Input::Path(value.into()))
    }
}

/// Parses key/value pairs split by the first equal sign.
///
/// This function will return an error if the argument contains no equals sign
/// or contains the key (before the equals sign) is empty.
fn parse_input_pair(raw: &str) -> Result<(String, String), String> {
    let (key, val) = raw
        .split_once('=')
        .ok_or("input must be a key and a value separated by an equal sign")?;
    let key = key.trim().to_owned();
    if key.is_empty() {
        return Err("the key was missing or empty".to_owned());
    }
    let val = val.trim().to_owned();