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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
use clap::{Args, Subcommand};
use crate::cli::common::normalize_str_vec;
mod read;
mod write;
#[derive(Args)]
pub struct IssueArgs {
#[command(subcommand)]
pub command: IssueCommand,
}
#[derive(Subcommand)]
pub enum IssueCommand {
/// List issues
List {
/// Filter by state (open, closed, all)
#[arg(
long,
short,
default_value = "open",
value_parser = ["open", "closed", "all"],
ignore_case = true
)]
state: String,
/// Output as JSON
#[arg(long)]
json: bool,
/// Do not use a pager
#[arg(long)]
no_pager: bool,
},
/// View an issue (use --comments to include comments)
View {
/// Issue number
number: u64,
/// Include comments in the output
#[arg(long, short)]
comments: bool,
/// Open in browser
#[arg(long, short)]
web: bool,
/// Print raw JSON response
#[arg(long)]
json: bool,
/// Do not use a pager
#[arg(long)]
no_pager: bool,
},
/// Create a new issue
Create {
/// Issue title (prompts when omitted)
#[arg(long, short)]
title: Option<String>,
/// Issue body (prompts when omitted)
#[arg(long, short)]
body: Option<String>,
/// Label name (repeatable or comma-separated)
#[arg(long, short, value_delimiter = ',')]
label: Vec<String>,
/// Assignee username (repeatable or comma-separated)
#[arg(long, short, value_delimiter = ',')]
assignee: Vec<String>,
},
/// Edit an issue
Edit {
/// Issue number
number: u64,
/// New issue title
#[arg(long, short)]
title: Option<String>,
/// New issue body
#[arg(long, short)]
body: Option<String>,
/// Add label name (repeatable or comma-separated)
#[arg(long = "add-label", value_delimiter = ',')]
add_label: Vec<String>,
/// Remove label name (repeatable or comma-separated)
#[arg(long = "remove-label", value_delimiter = ',')]
remove_label: Vec<String>,
/// Add assignee username (repeatable or comma-separated)
#[arg(long = "add-assignee", value_delimiter = ',')]
add_assignee: Vec<String>,
/// Remove assignee username (repeatable or comma-separated)
#[arg(long = "remove-assignee", value_delimiter = ',')]
remove_assignee: Vec<String>,
/// Set milestone number
#[arg(long)]
milestone: Option<u64>,
/// Remove the current milestone
#[arg(long)]
remove_milestone: bool,
/// Update issue state (open or closed)
#[arg(long, value_parser = ["open", "closed"], ignore_case = true)]
state: Option<String>,
},
/// Close an issue
Close {
/// Issue number
number: u64,
},
/// Reopen an issue
Reopen {
/// Issue number
number: u64,
},
/// Add or edit a comment on an issue
Comment {
/// Issue number
number: u64,
/// Comment body (prompts when omitted)
#[arg(long, short)]
body: Option<String>,
/// Edit your last comment instead of adding a new one
#[arg(long)]
edit_last: bool,
},
}
pub async fn run(
args: IssueArgs,
cli_hostname: &Option<String>,
cli_repo: &Option<String>,
cli_profile: &Option<String>,
) -> crate::error::Result<()> {
match args.command {
IssueCommand::List {
state,
json,
no_pager,
} => read::list(cli_hostname, cli_repo, cli_profile, &state, json, no_pager).await,
IssueCommand::View {
number,
comments,
web,
json,
no_pager,
} => {
read::view(
cli_hostname,
cli_repo,
cli_profile,
read::ViewOptions {
number,
show_comments: comments,
web,
json,
no_pager,
},
)
.await
}
IssueCommand::Create {
title,
body,
label,
assignee,
} => {
write::create(
cli_hostname,
cli_repo,
cli_profile,
title,
body,
normalize_str_vec(label),
normalize_str_vec(assignee),
)
.await
}
IssueCommand::Edit {
number,
title,
body,
add_label,
remove_label,
add_assignee,
remove_assignee,
milestone,
remove_milestone,
state,
} => {
write::edit(
cli_hostname,
cli_repo,
cli_profile,
write::EditRequest {
number,
title,
body,
add_labels: normalize_str_vec(add_label),
remove_labels: normalize_str_vec(remove_label),
add_assignees: normalize_str_vec(add_assignee),
remove_assignees: normalize_str_vec(remove_assignee),
milestone,
remove_milestone,
state,
},
)
.await
}
IssueCommand::Close { number } => {
write::close(cli_hostname, cli_repo, cli_profile, number).await
}
IssueCommand::Reopen { number } => {
write::reopen(cli_hostname, cli_repo, cli_profile, number).await
}
IssueCommand::Comment {
number,
body,
edit_last,
} => write::comment(cli_hostname, cli_repo, cli_profile, number, body, edit_last).await,
}
}