Skip to main content

es_fluent_cli/commands/
generate.rs

1//! Generate command implementation.
2
3use crate::commands::{
4    GenerationVerb, WorkspaceArgs, WorkspaceCrates, parallel_generate,
5    render_generation_results_with_dry_run,
6};
7use crate::core::{CliError, FluentParseMode, GenerationAction};
8use crate::utils::ui;
9use clap::Parser;
10
11/// Arguments for the generate command.
12#[derive(Parser)]
13pub struct GenerateArgs {
14    #[command(flatten)]
15    pub workspace: WorkspaceArgs,
16
17    /// Parse mode for FTL generation
18    #[arg(short, long, value_enum, default_value_t = FluentParseMode::default())]
19    pub mode: FluentParseMode,
20
21    /// Dry run - show what would be generated without making changes.
22    #[arg(long)]
23    pub dry_run: bool,
24
25    /// Force rebuild of the runner, ignoring the staleness cache.
26    #[arg(long)]
27    pub force_run: bool,
28}
29
30/// Run the generate command.
31pub fn run_generate(args: GenerateArgs) -> Result<(), CliError> {
32    let workspace = WorkspaceCrates::discover(args.workspace)?;
33
34    if !workspace.print_discovery(ui::print_header) {
35        return Ok(());
36    }
37
38    let results = parallel_generate(
39        &workspace.workspace_info,
40        &workspace.valid,
41        &GenerationAction::Generate {
42            mode: args.mode,
43            dry_run: args.dry_run,
44        },
45        args.force_run,
46    );
47    let has_errors =
48        render_generation_results_with_dry_run(&results, args.dry_run, GenerationVerb::Generate);
49
50    if has_errors {
51        std::process::exit(1);
52    }
53
54    Ok(())
55}