twin_cli/
cli.rs

1// This file is kept for backward compatibility
2// The actual CLI implementation is now in cli/mod.rs
3
4pub mod commands;
5mod output;
6
7use clap::{Parser, Subcommand};
8use std::path::PathBuf;
9
10/// CLIのメインエントリーポイント
11/// clapのderiveマクロを使って自動的にコマンドライン引数をパース
12#[derive(Parser)]
13#[command(name = "twin")]
14#[command(about = "Git worktree and symlink environment manager", long_about = None)]
15pub struct Cli {
16    #[command(subcommand)]
17    pub command: Commands,
18}
19
20/// 利用可能なサブコマンドの定義
21#[derive(Subcommand)]
22pub enum Commands {
23    /// ワークツリーを追加(git worktree add)
24    Add(AddArgs),
25
26    /// ワークツリーを追加(addのエイリアス、後方互換性のため)
27    Create(AddArgs),
28
29    /// 全てのワークツリーをリスト表示
30    #[command(alias = "ls")]
31    List(ListArgs),
32
33    /// ワークツリーを削除
34    #[command(alias = "delete")]
35    Remove(RemoveArgs),
36
37    /// 設定を管理
38    Config(ConfigArgs),
39
40    /// TUIインターフェースを起動
41    Tui,
42}
43
44/// addコマンドの引数(git worktree addと互換)
45#[derive(Parser)]
46pub struct AddArgs {
47    /// ワークツリーのパス
48    pub path: PathBuf,
49
50    /// ブランチ名またはコミット(省略時はパスから推測)
51    pub branch: Option<String>,
52
53    /// 新しいブランチを作成
54    #[arg(short = 'b', long)]
55    pub new_branch: Option<String>,
56
57    /// 新しいブランチを強制的に作成
58    #[arg(short = 'B', long)]
59    pub force_branch: Option<String>,
60
61    /// デタッチモード
62    #[arg(short = 'd', long)]
63    pub detach: bool,
64
65    /// ロックする
66    #[arg(long)]
67    pub lock: bool,
68
69    /// 追跡モードを設定
70    #[arg(long)]
71    pub track: bool,
72
73    /// 追跡モードを無効
74    #[arg(long)]
75    pub no_track: bool,
76
77    /// リモートブランチを推測
78    #[arg(long)]
79    pub guess_remote: bool,
80
81    /// リモートブランチを推測しない
82    #[arg(long)]
83    pub no_guess_remote: bool,
84
85    /// チェックアウトしない
86    #[arg(long)]
87    pub no_checkout: bool,
88
89    /// quietモード
90    #[arg(short = 'q', long)]
91    pub quiet: bool,
92
93    /// twin固有: 設定ファイルのパス
94    #[arg(short = 'c', long)]
95    pub config: Option<PathBuf>,
96
97    /// twin固有: 作成後にパスを表示
98    #[arg(long)]
99    pub print_path: bool,
100
101    /// twin固有: 作成後にcdコマンドを表示
102    #[arg(long)]
103    pub cd_command: bool,
104
105    /// twin固有: 副作用をスキップしてgit worktreeのみ実行
106    #[arg(long)]
107    pub git_only: bool,
108}
109
110/// listコマンドの引数
111#[derive(Parser)]
112pub struct ListArgs {
113    /// 出力フォーマット (table, json, simple)
114    #[arg(short, long, default_value = "table")]
115    pub format: String,
116}
117
118/// removeコマンドの引数(git worktree removeと互換)
119#[derive(Parser)]
120pub struct RemoveArgs {
121    /// 削除するワークツリーのパスまたは名前
122    pub worktree: String,
123
124    /// 確認なしで強制削除
125    #[arg(short, long)]
126    pub force: bool,
127
128    /// 設定ファイルのパス
129    #[arg(short, long, value_name = "FILE")]
130    pub config: Option<PathBuf>,
131
132    /// git worktree removeのみ実行(副作用をスキップ)
133    #[arg(long)]
134    pub git_only: bool,
135
136    /// 出力を抑制
137    #[arg(short, long)]
138    pub quiet: bool,
139}
140
141/// configコマンドの引数
142#[derive(Parser)]
143pub struct ConfigArgs {
144    /// サブコマンド(default, show, etc)
145    pub subcommand: Option<String>,
146
147    /// 現在の設定を表示
148    #[arg(long)]
149    pub show: bool,
150
151    /// 設定値をセット (key=value形式)
152    #[arg(long)]
153    pub set: Option<String>,
154
155    /// 設定値を取得
156    #[arg(long)]
157    pub get: Option<String>,
158}