Skip to main content

cargo_mate/cmd/
smune.rs

1use clap::{Parser, Subcommand, ValueEnum};
2use std::path::PathBuf;
3#[derive(Parser, Debug)]
4#[command(name = "cm")]
5#[command(about = "Cargo Mate", long_about = None)]
6#[command(version, author)]
7pub struct Args {
8    #[command(subcommand)]
9    pub command: Option<Commands>,
10    #[arg(trailing_var_arg = true)]
11    pub args: Vec<String>,
12}
13#[derive(Subcommand, Debug, Clone)]
14pub enum Commands {
15    Init,
16    Journey { #[command(subcommand)] action: JourneyAction },
17    Anchor { #[command(subcommand)] action: AnchorAction },
18    Log { #[command(subcommand)] action: LogAction },
19    Tide { #[command(subcommand)] action: TideAction },
20    Map { #[command(subcommand)] action: MapAction },
21    Mutiny { #[command(subcommand)] action: MutinyAction },
22    Config { #[command(subcommand)] action: crate::ConfigAction },
23    Version { #[command(subcommand)] action: VersionAction },
24    View { #[command(subcommand)] action: ViewAction },
25    Test,
26    Probe { #[command(subcommand)] action: crate::probe::ProbeAction },
27    Optimize { #[command(subcommand)] action: OptimizeAction },
28    Checklist { #[command(subcommand)] action: ChecklistAction },
29    History {
30        #[arg(default_value = "summary")]
31        kind: String,
32        #[arg(default_value = "50")]
33        limit: usize,
34    },
35    Scrub { #[command(subcommand)] action: ScrubAction },
36    Sweep { #[command(subcommand)] action: crate::sweeping::SweepCommands },
37    Install,
38    Activate,
39    Exec {
40        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
41        cargo_args: Vec<String>,
42    },
43    Register {
44        license_key: Option<String>,
45        #[arg(long)]
46        status: bool,
47        #[arg(long)]
48        remaining: bool,
49    },
50    Idea { idea: String },
51    Wtf { #[command(subcommand)] action: crate::captain::wtf::WtfAction },
52    User,
53    Debug,
54    Strip(crate::strip::StripArgs),
55    Scat { #[command(subcommand)] command: crate::scat::ScatCommand },
56    Tool { #[command(subcommand)] action: ToolAction },
57    Ddr { #[command(subcommand)] action: DockDockRustCommands },
58    Deps {
59        #[arg(long)]
60        path: Option<PathBuf>,
61        #[arg(long)]
62        json: bool,
63    },
64    Liberate {
65        #[arg(short = 't', long, default_value = ".")]
66        target: PathBuf,
67        #[arg(short = 'o', long)]
68        out: Option<PathBuf>,
69    },
70    Tree {
71        #[command(subcommand)]
72        action: Option<TreeAction>,
73        #[arg(short = 't', long, default_value = ".")]
74        target: PathBuf,
75        #[arg(short = 'o', long)]
76        out: Option<PathBuf>,
77        #[arg(long)]
78        no_folders: bool,
79        #[arg(long)]
80        no_files: bool,
81        #[arg(long)]
82        folder_size: bool,
83        #[arg(long)]
84        file_size: bool,
85        #[arg(long)]
86        line_count: bool,
87        #[arg(long)]
88        dates: bool,
89        #[arg(long, default_value = "readme")]
90        style: String,
91        #[arg(long)]
92        yolo: bool,
93    },
94    Stub {
95        #[command(subcommand)]
96        action: Option<StubAction>,
97        #[arg(short = 't', long, default_value = ".")]
98        target: PathBuf,
99        #[arg(short = 'o', long)]
100        out: Option<PathBuf>,
101        #[arg(long)]
102        ext: Option<String>,
103        #[arg(long)]
104        custom: Option<String>,
105        #[arg(long)]
106        find: Option<String>,
107        #[arg(long)]
108        skip: Option<String>,
109    },
110    Bin {
111        #[command(subcommand)]
112        action: Option<BinAction>,
113        #[arg(short, long)]
114        path: Option<PathBuf>,
115        #[arg(short = 'n', long)]
116        name: Option<String>,
117        #[arg(short = 'o', long)]
118        out: Option<PathBuf>,
119        #[arg(long, default_value = "10")]
120        timeout_seconds: u64,
121        #[arg(long)]
122        max_depth: Option<usize>,
123    },
124}
125impl Commands {
126    pub fn name(&self) -> &'static str {
127        match self {
128            Commands::Init => "init",
129            Commands::Journey { .. } => "journey",
130            Commands::Anchor { .. } => "anchor",
131            Commands::Log { .. } => "log",
132            Commands::Tide { .. } => "tide",
133            Commands::Map { .. } => "map",
134            Commands::Mutiny { .. } => "mutiny",
135            Commands::Config { .. } => "config",
136            Commands::Version { .. } => "version",
137            Commands::View { .. } => "view",
138            Commands::Test => "test",
139            Commands::Probe { .. } => "probe",
140            Commands::Optimize { .. } => "optimize",
141            Commands::Checklist { .. } => "checklist",
142            Commands::History { .. } => "history",
143            Commands::Scrub { .. } => "scrub",
144            Commands::Install => "install",
145            Commands::Activate => "activate",
146            Commands::Exec { .. } => "exec",
147            Commands::Register { .. } => "register",
148            Commands::Idea { .. } => "idea",
149            Commands::Wtf { .. } => "wtf",
150            Commands::User => "user",
151            Commands::Debug => "debug",
152            Commands::Strip(_) => "strip",
153            Commands::Scat { .. } => "scat",
154            Commands::Sweep { action: _ } => "sweep",
155            Commands::Tool { .. } => "tool",
156            Commands::Ddr { .. } => "ddr",
157            Commands::Deps { .. } => "deps",
158            Commands::Liberate { .. } => "liberate",
159            Commands::Tree { .. } => "tree",
160            Commands::Stub { .. } => "stub",
161            Commands::Bin { .. } => "bin",
162        }
163    }
164}
165#[derive(Subcommand, Debug, Clone)]
166pub enum JourneyAction {
167    Record { name: String },
168    Play { name: String, #[arg(long)] dry_run: bool },
169    List,
170    Export { name: String, output: PathBuf },
171    Import { path: PathBuf },
172    Publish { name: String, #[arg(long)] tags: Vec<String> },
173    Download { gist_id: String },
174    Search { query: String },
175    Published,
176}
177#[derive(Subcommand, Debug, Clone)]
178pub enum AnchorAction {
179    Save { name: String, #[arg(long)] message: Option<String> },
180    Restore { name: String },
181    List,
182    Show { name: String },
183    Diff { name: String },
184    Auto { name: String, #[arg(long)] foreground: bool },
185    Stop { name: String },
186}
187#[derive(Subcommand, Debug, Clone)]
188pub enum LogAction {
189    Add { message: String, #[arg(long)] tags: Vec<String> },
190    Search { query: String },
191    Timeline { #[arg(default_value = "7")] days: i64 },
192    Export { path: PathBuf, #[arg(long, default_value = "markdown")] format: String },
193    Analyze,
194    Track { command: String },
195}
196#[derive(Subcommand, Debug, Clone)]
197pub enum TideAction {
198    Show,
199    Analyze,
200    Export { path: PathBuf },
201}
202#[derive(Subcommand, Debug, Clone)]
203pub enum MapAction {
204    Show,
205    Analyze,
206    Export { path: PathBuf },
207    Path { from: String, to: String },
208}
209#[derive(Subcommand, Debug, Clone)]
210pub enum MutinyAction {
211    Activate { reason: String },
212    Deactivate,
213    AllowWarnings,
214    SkipTests,
215    Force,
216    Yolo,
217    Status,
218}
219#[derive(Subcommand, Debug, Clone)]
220pub enum VersionAction {
221    Init { version: Option<String> },
222    Info,
223    Increment { increment_type: IncrementType },
224    Set { version: String },
225    History,
226    UpdateCargo,
227    Config { #[command(subcommand)] action: VersionConfigAction },
228}
229#[derive(Subcommand, Debug, Clone)]
230pub enum VersionConfigAction {
231    Enable,
232    Disable,
233    Policy { #[arg(value_enum)] policy: IncrementType },
234    Show,
235}
236#[derive(Debug, Clone, Copy, ValueEnum)]
237pub enum IncrementType {
238    Patch,
239    Minor,
240    Major,
241}
242#[derive(Subcommand, Debug, Clone)]
243pub enum ViewAction {
244    Errors,
245    Artifacts,
246    Scripts,
247    History,
248    Checklist,
249    All,
250    Latest,
251    Open,
252}
253#[derive(Subcommand, Debug, Clone)]
254pub enum OptimizeAction {
255    Aggressive,
256    Balanced,
257    Conservative,
258    Custom {
259        #[arg(default_value = "4")]
260        jobs: u32,
261        #[arg(default_value = "true")]
262        incremental: String,
263        #[arg(default_value = "3")]
264        opt_level: u32,
265        #[arg(default_value = "0")]
266        debug_level: u32,
267        #[arg(default_value = "128")]
268        codegen_units: u32,
269    },
270    Status,
271    Recommendations,
272    Restore,
273}
274#[derive(Subcommand, Debug, Clone)]
275pub enum ChecklistAction {
276    Show,
277    List,
278    Add { item: String },
279    Done { items: String },
280    Clear { #[arg(default_value = "done")] target: String },
281}
282#[derive(Subcommand, Debug, Clone)]
283pub enum ScrubAction {
284    Run {
285        #[arg(long)]
286        dry_run: bool,
287        #[arg(short, long)]
288        verbose: bool,
289        #[arg(short, long, default_value = "/")]
290        start: String,
291        #[arg(short, long)]
292        resume: Option<String>,
293        #[arg(long, default_value = "1")]
294        min_depth: usize,
295        #[arg(long, default_value = "10")]
296        max_depth: usize,
297    },
298    Help,
299}
300#[derive(Subcommand, Debug, Clone)]
301pub enum ToolAction {
302    List,
303    Help { name: String },
304    Run { name: String, #[arg(trailing_var_arg = true)] args: Vec<String> },
305    #[command(external_subcommand)]
306    Execute(Vec<String>),
307}
308#[derive(Subcommand, Debug, Clone)]
309pub enum SweepAction {
310    Scan {
311        #[arg(default_value = ".")]
312        path: PathBuf,
313        #[arg(long)]
314        include_tests: bool,
315        #[arg(long)]
316        include_examples: bool,
317    },
318    Clean {
319        #[arg(default_value = ".")]
320        path: PathBuf,
321        #[arg(long)]
322        dry_run: bool,
323        #[arg(long)]
324        force: bool,
325    },
326    Init,
327    Help,
328}
329#[derive(Subcommand, Debug, Clone)]
330pub enum DdrCommands {
331    #[command(flatten)]
332    DockDockRust(DockDockRustCommands),
333}
334#[derive(Subcommand, Debug, Clone)]
335pub enum DockDockRustCommands {
336    DockDockRust {
337        /// Docker image to use
338        #[arg(short, long, default_value = "rust:latest")]
339        image: String,
340        /// Path to Cargo.toml
341        #[arg(short = 'c', long, default_value = "Cargo.toml")]
342        cargo: PathBuf,
343        /// Source directory
344        #[arg(short = 's', long, default_value = "src")]
345        src: PathBuf,
346        /// Build targets (can specify multiple)
347        #[arg(short = 't', long)]
348        target: Vec<String>,
349        /// Configuration file
350        #[arg(short = 'f', long, default_value = "ddr.toml")]
351        config: PathBuf,
352        /// Maximum parallel jobs
353        #[arg(short = 'j', long, default_value = "16")]
354        jobs: usize,
355        /// Generate config only
356        #[arg(long)]
357        gen_config: bool,
358        /// Verbose output
359        #[arg(short, long)]
360        verbose: bool,
361    },
362}
363#[derive(Subcommand, Debug, Clone)]
364pub enum TreeAction {
365    History,
366    Show { name: String },
367    Find { query: String },
368}
369#[derive(Subcommand, Debug, Clone)]
370pub enum StubAction {
371    Find { pattern: Option<String> },
372    Skip { patterns: String },
373    History,
374    Show { name: String },
375    Delete { #[arg(long)] all: bool },
376}
377#[derive(Subcommand, Debug, Clone)]
378pub enum BinAction {
379    History,
380    Show { name: String },
381    Find { query: String },
382    Delete { #[arg(long)] all: bool },
383}