1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
use clap::{Args, Subcommand};
use crate::error::Result;
mod git;
mod read;
mod write;
#[derive(Args)]
pub struct RepoArgs {
#[command(subcommand)]
pub command: RepoCommand,
}
#[derive(Subcommand)]
pub enum RepoCommand {
/// List repositories
List {
/// Owner (user or group). If omitted, lists your repositories.
#[arg(value_name = "OWNER")]
owner: Option<String>,
/// Output as JSON
#[arg(long)]
json: bool,
},
/// View repository details
View {
/// Target repository in OWNER/REPO format
#[arg(long = "repo", short = 'R', value_name = "OWNER/REPO")]
target_repo: Option<String>,
/// Repository in OWNER/REPO format (defaults to -R or git remote)
#[arg(value_name = "OWNER/REPO")]
repo: Option<String>,
/// Open in browser
#[arg(long, short)]
web: bool,
},
/// Create a new repository
Create {
/// Repository name (prompts when omitted)
name: Option<String>,
/// Description
#[arg(long, short)]
description: Option<String>,
/// Make the repository private
#[arg(long)]
private: bool,
/// Initialize with a README
#[arg(long)]
add_readme: bool,
/// Group to create under
#[arg(long = "group")]
group: Option<String>,
},
/// Clone a repository
#[command(
after_long_help = "OWNER/REPO uses configured GitBucket credentials on the selected instance. See docs/usage/authentication.md."
)]
Clone {
/// Repository to clone (OWNER/REPO or full URL)
#[arg(value_name = "OWNER/REPO|URL")]
repo: String,
/// Directory to clone into
directory: Option<String>,
},
/// Delete a repository and verify that it is absent
Delete {
/// Target repository in OWNER/REPO format
#[arg(long = "repo", short = 'R', value_name = "OWNER/REPO")]
target_repo: Option<String>,
/// Skip confirmation
#[arg(long)]
yes: bool,
/// Repository in OWNER/REPO format (or -R/--repo)
#[arg(value_name = "OWNER/REPO")]
repo: Option<String>,
},
/// Fork a repository and verify its destination and immediate parent
Fork {
/// Target repository in OWNER/REPO format
#[arg(long = "repo", short = 'R', value_name = "OWNER/REPO")]
target_repo: Option<String>,
/// Repository to fork (OWNER/REPO, or -R/--repo)
#[arg(value_name = "OWNER/REPO")]
repo: Option<String>,
/// Group to fork into (defaults to the REST token's user)
#[arg(long = "group")]
group: Option<String>,
},
}
pub async fn run(
args: RepoArgs,
cli_hostname: &Option<String>,
cli_repo: &Option<String>,
cli_profile: &Option<String>,
) -> Result<()> {
match args.command {
RepoCommand::List { owner, json } => {
read::list(cli_hostname, cli_profile, owner, json).await
}
RepoCommand::View {
target_repo,
repo,
web,
} => {
read::view(
cli_hostname,
repo.or(target_repo).or(cli_repo.clone()),
cli_profile,
web,
)
.await
}
RepoCommand::Create {
name,
description,
private,
add_readme,
group,
} => {
write::create(
cli_hostname,
cli_profile,
name,
description,
private,
add_readme,
group,
)
.await
}
RepoCommand::Clone { repo, directory } => {
git::clone(cli_hostname, cli_profile, &repo, directory.as_deref()).await
}
RepoCommand::Delete {
target_repo,
repo,
yes,
} => {
write::delete(
cli_hostname,
cli_profile,
repo.or(target_repo).or(cli_repo.clone()),
yes,
)
.await
}
RepoCommand::Fork {
target_repo,
repo,
group,
} => {
write::fork(
cli_hostname,
repo.or(target_repo).or(cli_repo.clone()),
cli_profile,
group,
)
.await
}
}
}