Skip to main content

es_fluent_cli/commands/clean/
mod.rs

1//! Clean command implementation.
2
3mod orphaned;
4
5use crate::commands::{
6    GenerationVerb, WorkspaceArgs, WorkspaceCrates, parallel_generate,
7    render_generation_results_with_dry_run,
8};
9use crate::core::{CliError, GenerationAction};
10use crate::utils::ui;
11use clap::Parser;
12
13use orphaned::clean_orphaned_files;
14
15/// Arguments for the clean command.
16#[derive(Parser)]
17pub struct CleanArgs {
18    #[command(flatten)]
19    pub workspace: WorkspaceArgs,
20
21    /// Clean all locales, not just the fallback language.
22    #[arg(long)]
23    pub all: bool,
24
25    /// Dry run - show what would be cleaned without making changes.
26    #[arg(long)]
27    pub dry_run: bool,
28
29    /// Force rebuild of the runner, ignoring the staleness cache.
30    #[arg(long)]
31    pub force_run: bool,
32
33    /// Remove orphaned FTL files that are no longer tied to any types.
34    /// This removes files that don't correspond to any registered types
35    /// (e.g., when all items are now namespaced or the crate was deleted).
36    #[arg(long)]
37    pub orphaned: bool,
38}
39
40/// Run the clean command.
41pub fn run_clean(args: CleanArgs) -> Result<(), CliError> {
42    let workspace = WorkspaceCrates::discover(args.workspace)?;
43
44    if !workspace.print_discovery(ui::print_header) {
45        return Ok(());
46    }
47
48    // Handle orphaned file removal first if requested
49    if args.orphaned {
50        return clean_orphaned_files(&workspace, args.all, args.dry_run);
51    }
52
53    let action = GenerationAction::Clean {
54        all_locales: args.all,
55        dry_run: args.dry_run,
56    };
57
58    let results = parallel_generate(
59        &workspace.workspace_info,
60        &workspace.valid,
61        &action,
62        args.force_run,
63    );
64    let has_errors =
65        render_generation_results_with_dry_run(&results, args.dry_run, GenerationVerb::Clean);
66
67    if has_errors {
68        std::process::exit(1);
69    }
70
71    Ok(())
72}