git_x/
cli.rs

1use clap::Parser;
2
3#[derive(Parser)]
4pub struct Cli {
5    #[clap(subcommand)]
6    pub command: Commands,
7}
8
9#[derive(clap::Subcommand)]
10pub enum Commands {
11    #[clap(about = "Rename the current branch")]
12    RenameBranch {
13        #[clap(help = "New name for the current branch")]
14        new_name: String,
15    },
16    #[clap(about = "Delete merged local branches (except protected ones)")]
17    PruneBranches {
18        #[clap(
19            long = "except",
20            value_name = "branches",
21            help = "Comma-separated list of branches to exclude"
22        )]
23        except: Option<String>,
24    },
25    #[clap(about = "Show a high-level overview of the current repo")]
26    Info,
27    #[clap(about = "Pretty Git log with branches, remotes, and HEADs")]
28    Graph,
29    #[clap(about = "Colorized Git log with branches, remotes, and HEADs")]
30    ColorGraph,
31    #[clap(about = "Check repository health and show potential issues")]
32    Health,
33    #[clap(about = "Show commits since a reference (e.g., cb676ec, origin/main)")]
34    Since {
35        #[clap(help = "Reference point")]
36        reference: String,
37    },
38    #[clap(about = "Undo the last commit (without losing changes)")]
39    Undo,
40    #[clap(about = "Delete all fully merged local branches (except protected ones)")]
41    CleanBranches {
42        #[clap(long = "dry-run", help = "Prints the branches it would delete instead of actually deleting them", action = clap::ArgAction::SetTrue)]
43        dry_run: bool,
44    },
45    #[clap(about = "Show what’s different between this branch and another (default: main)")]
46    What {
47        #[clap(long = "target", help = "Branch to compare to")]
48        target: Option<String>,
49    },
50    #[clap(about = "Show a short, changelog-style summary of recent commits")]
51    Summary {
52        #[clap(
53            long = "since",
54            help = "Accepts flexible formats like \"yesterday\", \"3 days ago\", \"2025-07-01\", etc. (same as git log --since)"
55        )]
56        since: String,
57    },
58    #[clap(about = "Sync current branch with upstream (fetch + rebase)")]
59    Sync {
60        #[clap(long = "merge", help = "Use merge instead of rebase", action = clap::ArgAction::SetTrue)]
61        merge: bool,
62    },
63    #[clap(about = "Create and switch to a new branch")]
64    New {
65        #[clap(help = "Name of the new branch")]
66        branch_name: String,
67        #[clap(
68            long = "from",
69            help = "Base branch to create from (default: current branch)"
70        )]
71        from: Option<String>,
72    },
73    #[clap(about = "Find largest files in repository history")]
74    LargeFiles {
75        #[clap(long = "limit", default_value = "10", help = "Number of files to show")]
76        limit: usize,
77        #[clap(
78            long = "threshold",
79            help = "Minimum file size in MB (default: show all)"
80        )]
81        threshold: Option<f64>,
82    },
83    #[clap(about = "Create fixup commits for easier interactive rebasing")]
84    Fixup {
85        #[clap(help = "Commit hash to create fixup for")]
86        commit_hash: String,
87        #[clap(long = "rebase", help = "Automatically rebase with autosquash after creating fixup", action = clap::ArgAction::SetTrue)]
88        rebase: bool,
89    },
90    #[clap(about = "Advanced stash management with branch integration")]
91    StashBranch {
92        #[clap(subcommand)]
93        action: StashBranchAction,
94    },
95    #[clap(about = "Manage upstream branch relationships")]
96    Upstream {
97        #[clap(subcommand)]
98        action: UpstreamAction,
99    },
100}
101
102#[derive(clap::Subcommand)]
103pub enum StashBranchAction {
104    #[clap(about = "Create a new branch from a stash")]
105    Create {
106        #[clap(help = "Name for the new branch")]
107        branch_name: String,
108        #[clap(long = "stash", help = "Stash reference (default: latest stash)")]
109        stash_ref: Option<String>,
110    },
111    #[clap(about = "Clean old stashes")]
112    Clean {
113        #[clap(
114            long = "older-than",
115            help = "Remove stashes older than (e.g., '7d', '2w', '1m')"
116        )]
117        older_than: Option<String>,
118        #[clap(long = "dry-run", help = "Show what would be cleaned without doing it", action = clap::ArgAction::SetTrue)]
119        dry_run: bool,
120    },
121    #[clap(about = "Apply stashes from a specific branch")]
122    ApplyByBranch {
123        #[clap(help = "Branch name to filter stashes by")]
124        branch_name: String,
125        #[clap(long = "list", help = "List stashes instead of applying", action = clap::ArgAction::SetTrue)]
126        list_only: bool,
127    },
128}
129
130#[derive(clap::Subcommand)]
131pub enum UpstreamAction {
132    #[clap(about = "Set upstream for current branch")]
133    Set {
134        #[clap(help = "Upstream branch reference (e.g., origin/main)")]
135        upstream: String,
136    },
137    #[clap(about = "Show upstream status for all branches")]
138    Status,
139    #[clap(about = "Sync all local branches with their upstreams")]
140    SyncAll {
141        #[clap(long = "dry-run", help = "Show what would be synced without doing it", action = clap::ArgAction::SetTrue)]
142        dry_run: bool,
143        #[clap(long = "merge", help = "Use merge instead of rebase", action = clap::ArgAction::SetTrue)]
144        merge: bool,
145    },
146}