Skip to main content

crab_clean/cli/
commands.rs

1pub mod duplicate;
2pub mod unused;
3
4use crate::{
5    cli::commands::{
6        duplicate::{duplicate_with_dry_run, duplicate_with_run},
7        unused::{unused_with_dry_run, unused_with_run},
8    },
9    config::settings::{Cli, Commands},
10    error::CrabcleanError,
11};
12
13pub fn dispatch_command(cli: &Cli) -> Result<(), CrabcleanError> {
14    match &cli.command {
15        Commands::Duplicate { path, dry_run } => {
16            if *dry_run {
17                println!("Dry run for duplicate command at path: {:?}", path);
18                duplicate_with_dry_run(path)?;
19            } else if !*dry_run {
20                println!("Executing duplicate command at path: {:?}", path);
21                duplicate_with_run(path)?;
22            } else {
23                return Err(CrabcleanError::Config(
24                    "Unused command not yet implemented".to_string(),
25                ));
26            }
27        }
28        Commands::Unused { path, age, dry_run } => {
29            if *dry_run {
30                println!(
31                    "Unused command with dry run: path={:?}, age={}, dry_run={}",
32                    path, age, dry_run
33                );
34                unused_with_dry_run(path, age)?;
35            } else if !*dry_run {
36                println!(
37                    "Unused command with dry run: path={:?}, age={}, dry_run={}",
38                    path, age, dry_run
39                );
40                unused_with_run(path, age)?;
41            } else {
42                return Err(CrabcleanError::Config(
43                    "Unused command not yet implemented".to_string(),
44                ));
45            }
46        }
47        Commands::Group {
48            path,
49            group_by,
50            dry_run,
51        } => {
52            if *dry_run {
53                println!("Group by dry run at {:?}, group_by {group_by}", path);
54            } else if !*dry_run {
55                println!("Group by run at {:?}, group_by {group_by}", path);
56            } else {
57                return Err(CrabcleanError::Config(
58                    "Unused command not yet implemented".to_string(),
59                ));
60            }
61        }
62    }
63    Ok(())
64}