lingora_cli/args.rs
1use std::path::{Path, PathBuf};
2
3use clap::{Parser, ValueEnum};
4use lingora_core::prelude::CoreArgs;
5
6/// Controls the level of output produced by `lingora-cli`.
7#[derive(Clone, Copy, Debug, ValueEnum)]
8pub enum OutputMode {
9 /// Enables lingora to complete the error checks on the reference and target files, returning an
10 /// error status if found. No detailed report will be produced.
11 Silent,
12 /// Output analysis report details to stdout.
13 Standard,
14}
15
16/// Command-line arguments specific to the `lingora-cli` binary.
17///
18/// Extends the shared `CoreArgs` (from `lingora-core`) with CLI-only options:
19/// - Output verbosity/behavior
20/// - Optional generation of `dioxus_i18n::I18nConfig` Rust code
21#[derive(Debug, Parser)]
22#[command(
23 name = env!("CARGO_PKG_NAME"),
24 version = env!("CARGO_PKG_VERSION"),
25 about = env!("CARGO_PKG_DESCRIPTION"),
26)]
27pub struct CliArgs {
28 #[command(flatten)]
29 core_args: CoreArgs,
30
31 #[arg(short, long = "output", value_enum, default_value_t = OutputMode::Standard)]
32 output_mode: OutputMode,
33
34 /// If provided, then the given file will be created, and will contain the
35 /// function `pub fn config(initial_language) -> I18nConfig { ... }'.
36 ///
37 /// See <https://docs.rs/dioxus-i18n/latest/dioxus_i18n/>.
38 #[arg(long)]
39 dioxus_i18n_config_file: Option<PathBuf>,
40}
41
42impl CliArgs {
43 /// Returns a reference to the shared core arguments.
44 pub fn core_args(&self) -> &CoreArgs {
45 &self.core_args
46 }
47
48 /// Returns the path where the generated Dioxus i18n config should be written.
49 pub fn dioxus_i18n_config_file(&self) -> Option<&Path> {
50 self.dioxus_i18n_config_file.as_deref()
51 }
52
53 /// Returns the selected output mode.
54 pub fn output_mode(&self) -> &OutputMode {
55 &self.output_mode
56 }
57}