Skip to main content

crab_clean/config/
settings.rs

1use clap::{Parser, Subcommand};
2use std::path::PathBuf;
3
4#[derive(Parser, Debug)]
5#[command(
6    name = "crabclean",
7    version = "0.1.0",
8    about = "Clean up your file system",
9    long_about = "
10Clean up your file system by finding and managing duplicate and unused files.
11
12USAGE:
13    crabclean <COMMAND> [OPTIONS] [PATH]
14
15COMMANDS:
16    duplicate    Find and manage duplicate files
17    unused       Find and manage unused files
18    help         Print this message or the help of the given subcommand(s)
19
20FLAGS:
21    --dry-run, -n   Preview what would be deleted without actually deleting files.
22                    If omitted, you will be interactively prompted for each deletion.
23                    (Press Ctrl+C to exit at any prompt.)
24
25OPTIONS:
26    -a, --age <AGE>   (for 'unused' command) Age in days for a file to be considered unused (default: 30)
27    -h, --help        Print help information
28    -V, --version     Print version information
29
30EXAMPLES:
31    crabclean duplicate --dry-run
32    crabclean duplicate /path/to/dir --dry-run
33    crabclean duplicate ~/Downloads
34    crabclean unused ~/Documents --age 60 --dry-run
35    crabclean unused --age 90
36
37NOTES:
38    - If you omit the --dry-run flag, the tool will prompt you for each file before deletion.
39    - Use Ctrl+C at any prompt to safely exit without deleting files.
40    - For feature requests (like grouping files) or issues, please contact: your.email@example.com
41"
42)]
43#[command(propagate_version = true)]
44pub struct Cli {
45    #[command(subcommand)]
46    pub command: Commands,
47}
48
49#[derive(Subcommand, Debug)]
50pub enum Commands {
51    #[command(
52        about = "Find and manage duplicate files",
53        long_about = "Finds duplicate files in the specified directory using SHA-256 content hashing. Supports dry run and interactive deletion."
54    )]
55    Duplicate {
56        #[arg(default_value = ".")]
57        path: PathBuf,
58        #[arg(short = 'n', long)]
59        dry_run: bool,
60    },
61    #[command(
62        about = "Find and manage unused files",
63        long_about = "Finds files that have not been accessed for a specified number of days. Supports dry run and interactive deletion."
64    )]
65    Unused {
66        #[arg(default_value = ".")]
67        path: PathBuf,
68        #[arg(short, long, default_value_t = 30)]
69        age: u32,
70        #[arg(short = 'n', long)]
71        dry_run: bool,
72    },
73    Group {
74        #[arg(default_value = ".")]
75        path: PathBuf,
76        #[arg(short = 'g', long, default_value = "all")]
77        group_by: String,
78        #[arg(short = 'n', long)]
79        dry_run: bool,
80    },
81}
82
83pub fn parse_arguments() -> Cli {
84    Cli::parse()
85}