Skip to main content

ferrous_forge/commands/
mod.rs

1//! Command implementations for Ferrous Forge
2
3use clap::Subcommand;
4
5/// Available commands for Ferrous Forge
6#[derive(Subcommand)]
7pub enum Commands {
8    /// Initialize Ferrous Forge system-wide, or set up a project with --project
9    Init {
10        /// Force initialization even if already configured
11        #[arg(short, long)]
12        force: bool,
13        /// Set up project-level tooling (rustfmt.toml, clippy.toml, Cargo.toml lints,
14        /// .vscode/settings.json, CI workflow, and git hooks) in the current directory.
15        /// Requires an existing Rust project with Cargo.toml.
16        #[arg(short, long)]
17        project: bool,
18    },
19    /// Show status of Ferrous Forge installation and configuration
20    Status,
21    /// Update Ferrous Forge to the latest version
22    Update {
23        /// Update channel to use (stable, beta, nightly)
24        #[arg(long, default_value = "stable")]
25        channel: String,
26        /// Only update rules, not the binary
27        #[arg(short, long)]
28        rules_only: bool,
29        /// Show what would be updated without actually updating
30        #[arg(short, long)]
31        dry_run: bool,
32    },
33    /// Manage configuration settings
34    Config {
35        /// Set a configuration value (key=value)
36        #[arg(short, long)]
37        set: Option<String>,
38        /// Get a configuration value
39        #[arg(short, long)]
40        get: Option<String>,
41        /// List all configuration values
42        #[arg(short, long)]
43        list: bool,
44        /// Reset configuration to defaults
45        #[arg(short, long)]
46        reset: bool,
47        /// Show configuration sources from hierarchy
48        #[arg(long)]
49        sources: bool,
50        /// Migrate old configuration to hierarchical system
51        #[arg(long)]
52        migrate: bool,
53        /// Configuration level to use (system, user, project)
54        #[arg(long)]
55        level: Option<String>,
56    },
57    /// Validate a Rust project against standards
58    Validate {
59        /// Path to the project to validate (defaults to current directory)
60        path: Option<std::path::PathBuf>,
61        /// Generate AI-friendly compliance report
62        #[arg(long)]
63        ai_report: bool,
64        /// Compare with previous report
65        #[arg(long)]
66        compare_previous: bool,
67        /// Only check locked settings (edition, rust-version) — exits 1 if any locked violation
68        #[arg(long)]
69        locked_only: bool,
70    },
71    /// Rollback to a previous version
72    Rollback {
73        /// Version to rollback to
74        version: String,
75    },
76    /// Uninstall Ferrous Forge from the system
77    Uninstall {
78        /// Confirm uninstallation without prompting
79        #[arg(short, long)]
80        confirm: bool,
81    },
82    /// Rust version management
83    Rust {
84        /// Rust version management subcommand
85        #[command(subcommand)]
86        command: RustCommand,
87    },
88    /// Edition management
89    Edition {
90        /// Edition management subcommand
91        #[command(subcommand)]
92        command: EditionCommand,
93    },
94    /// Safety pipeline management
95    Safety {
96        /// Safety pipeline subcommand
97        #[command(subcommand)]
98        command: SafetyCommand,
99    },
100    /// Project template management
101    Template {
102        /// Template subcommand
103        #[command(subcommand)]
104        command: template::TemplateCommand,
105    },
106    /// Automatically fix code violations
107    Fix {
108        /// Path to the project to fix (defaults to current directory)
109        path: Option<std::path::PathBuf>,
110        /// Only fix specific violation types (comma-separated)
111        #[arg(long)]
112        only: Option<String>,
113        /// Skip specific violation types (comma-separated)
114        #[arg(long)]
115        skip: Option<String>,
116        /// Show what would be fixed without making changes
117        #[arg(long)]
118        dry_run: bool,
119        /// Fix at most this many violations (for testing)
120        #[arg(long)]
121        limit: Option<usize>,
122        /// Enable AI-powered analysis for complex violations
123        #[arg(long)]
124        ai_analysis: bool,
125    },
126}
127
128/// Rust version management subcommands
129#[derive(Subcommand)]
130pub enum RustCommand {
131    /// Check current Rust version and available updates
132    Check {
133        /// Show verbose output
134        #[arg(short, long)]
135        verbose: bool,
136    },
137    /// Get update recommendations
138    Recommend {
139        /// Only consider stable releases
140        #[arg(short, long)]
141        stable_only: bool,
142    },
143    /// List recent Rust releases
144    List {
145        /// Number of releases to show
146        #[arg(short, long, default_value = "10")]
147        count: usize,
148    },
149}
150
151/// Edition management subcommands
152#[derive(Subcommand)]
153pub enum EditionCommand {
154    /// Check edition compliance
155    Check {
156        /// Project path
157        #[arg(default_value = ".")]
158        path: std::path::PathBuf,
159    },
160    /// Migrate to a new edition
161    Migrate {
162        /// Target edition (2018, 2021, 2024)
163        #[arg(default_value = "2024")]
164        edition: String,
165        /// Skip backup creation
166        #[arg(long)]
167        no_backup: bool,
168        /// Run tests after migration
169        #[arg(long)]
170        test: bool,
171        /// Apply edition idioms
172        #[arg(long)]
173        idioms: bool,
174    },
175    /// Analyze edition compatibility
176    Analyze {
177        /// Project path
178        #[arg(default_value = ".")]
179        path: std::path::PathBuf,
180        /// Target edition
181        #[arg(default_value = "2024")]
182        edition: String,
183    },
184}
185
186/// Safety pipeline management subcommands
187#[derive(Subcommand)]
188pub enum SafetyCommand {
189    /// Check safety pipeline status
190    Status,
191    /// Install git hooks for safety pipeline
192    Install {
193        /// Force reinstall even if hooks already exist
194        #[arg(short, long)]
195        force: bool,
196        /// Project path
197        #[arg(default_value = ".")]
198        path: std::path::PathBuf,
199        /// Install cargo publish interception
200        #[arg(long)]
201        cargo: bool,
202    },
203    /// Run safety checks manually
204    Check {
205        /// Pipeline stage to check
206        #[arg(long, default_value = "pre-commit")]
207        stage: String,
208        /// Project path
209        #[arg(default_value = ".")]
210        path: std::path::PathBuf,
211        /// Show verbose output
212        #[arg(short, long)]
213        verbose: bool,
214    },
215    /// Test individual safety checks
216    Test {
217        /// Project path
218        #[arg(default_value = ".")]
219        path: std::path::PathBuf,
220    },
221}
222
223/// Configuration management command handlers.
224pub mod config;
225/// Edition management command handlers.
226pub mod edition;
227/// Automatic code violation fix command handlers.
228pub mod fix;
229/// Project and system initialization command handlers.
230pub mod init;
231/// Version rollback command handlers.
232pub mod rollback;
233/// Rust version management command handlers.
234pub mod rust;
235/// Safety pipeline command handlers.
236pub mod safety;
237/// Installation status display command handlers.
238pub mod status;
239/// Project template command handlers.
240pub mod template;
241/// Uninstall command handlers.
242pub mod uninstall;
243/// Self-update command handlers.
244pub mod update;
245/// Project validation command handlers.
246pub mod validate;