git_worktree_cli/
cli.rs

1use clap::{Parser, Subcommand};
2
3#[derive(Parser)]
4#[command(
5    name = "gwt",
6    version,
7    author,
8    about = "Git worktree management tool",
9    long_about = "A tool for managing git worktrees efficiently with hooks and configuration support",
10    disable_version_flag = true
11)]
12pub struct Cli {
13    /// Print version
14    #[arg(short = 'v', long = "version", action = clap::ArgAction::Version)]
15    pub version: (),
16
17    #[command(subcommand)]
18    pub command: Commands,
19}
20
21#[derive(Subcommand)]
22pub enum CompletionAction {
23    /// Generate completions to stdout
24    Generate {
25        /// Shell to generate completions for
26        #[arg(value_enum)]
27        shell: clap_complete::Shell,
28    },
29    /// Install completions for your shell
30    Install {
31        /// Shell to install completions for (auto-detected if not specified)
32        #[arg(value_enum)]
33        shell: Option<clap_complete::Shell>,
34    },
35}
36
37#[derive(Subcommand)]
38pub enum AuthAction {
39    /// Authenticate with GitHub
40    Github,
41    /// Authenticate with Bitbucket Cloud
42    BitbucketCloud {
43        #[command(subcommand)]
44        action: Option<BitbucketCloudAuthAction>,
45    },
46    /// Authenticate with Bitbucket Data Center
47    BitbucketDataCenter {
48        #[command(subcommand)]
49        action: Option<BitbucketDataCenterAuthAction>,
50    },
51}
52
53#[derive(Subcommand)]
54pub enum BitbucketCloudAuthAction {
55    /// Show setup instructions
56    Setup,
57    /// Test the authentication connection
58    Test,
59}
60
61#[derive(Subcommand)]
62pub enum BitbucketDataCenterAuthAction {
63    /// Show setup instructions
64    Setup,
65    /// Test the authentication connection
66    Test,
67}
68
69#[derive(clap::ValueEnum, Clone, Debug)]
70pub enum Provider {
71    /// GitHub repository
72    Github,
73    /// Bitbucket Cloud repository
74    BitbucketCloud,
75    /// Bitbucket Data Center repository
76    BitbucketDataCenter,
77}
78
79#[derive(Subcommand)]
80pub enum Commands {
81    /// Initialize a new worktree project from a repository URL
82    Init {
83        /// The repository URL to clone
84        repo_url: String,
85        /// Repository provider (required for unknown URLs)
86        #[arg(long, value_enum)]
87        provider: Option<Provider>,
88        /// Force overwrite existing directories
89        #[arg(short, long)]
90        force: bool,
91    },
92
93    /// Add a new worktree for a branch
94    Add {
95        /// Branch name (can include slashes like feature/branch-name)
96        branch_name: String,
97    },
98
99    /// List all worktrees in the current project
100    List {
101        /// Show only local worktrees (skip remote PRs)
102        #[arg(short, long)]
103        local: bool,
104    },
105
106    /// Remove a worktree
107    Remove {
108        /// Branch name to remove (current worktree if not specified)
109        branch_name: Option<String>,
110        /// Skip confirmation prompts
111        #[arg(short, long)]
112        force: bool,
113    },
114
115    /// Manage authentication for external services
116    Auth {
117        #[command(subcommand)]
118        action: AuthAction,
119    },
120
121    /// Generate or install shell completions
122    Completions {
123        /// Action to perform (defaults to generate)
124        #[command(subcommand)]
125        action: Option<CompletionAction>,
126    },
127}