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
use clap::{Args, Subcommand};
mod change;
mod due_date;
mod read;
mod write;
#[derive(Args)]
#[command(after_long_help = "Use an empty --description or --due-on to clear it.")]
pub struct MilestoneArgs {
#[command(subcommand)]
pub command: MilestoneCommand,
}
#[derive(Subcommand)]
pub enum MilestoneCommand {
/// List milestones
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,
},
/// View a milestone
View {
/// Milestone number
number: u64,
},
/// Create a milestone
Create {
/// Milestone title (prompts when omitted)
title: Option<String>,
/// Optional milestone description
#[arg(long, short)]
description: Option<String>,
/// Due date as YYYY-MM-DD or RFC3339
#[arg(long = "due-on")]
due_on: Option<String>,
},
/// Edit a milestone
#[command(
after_long_help = "When using a Web edit, explicitly set or clear an existing due date."
)]
Edit {
/// Milestone number
number: u64,
/// Updated title
#[arg(long, short)]
title: Option<String>,
/// Updated description, or an empty string to clear
#[arg(long, short)]
description: Option<String>,
/// Updated due date as YYYY-MM-DD, RFC3339, or an empty string to clear
#[arg(long = "due-on")]
due_on: Option<String>,
/// Updated state (open or closed)
#[arg(long, short, value_parser = ["open", "closed"], ignore_case = true)]
state: Option<String>,
},
/// Delete a milestone
Delete {
/// Milestone number
number: u64,
/// Skip confirmation
#[arg(long)]
yes: bool,
},
}
pub async fn run(
args: MilestoneArgs,
cli_hostname: &Option<String>,
cli_repo: &Option<String>,
cli_profile: &Option<String>,
) -> crate::error::Result<()> {
match args.command {
MilestoneCommand::List { state, json } => {
read::list(cli_hostname, cli_repo, cli_profile, &state, json).await
}
MilestoneCommand::View { number } => {
read::view(cli_hostname, cli_repo, cli_profile, number).await
}
MilestoneCommand::Create {
title,
description,
due_on,
} => {
write::create(
cli_hostname,
cli_repo,
cli_profile,
title,
description,
due_on,
)
.await
}
MilestoneCommand::Edit {
number,
title,
description,
due_on,
state,
} => {
write::edit(
cli_hostname,
cli_repo,
cli_profile,
write::EditRequest {
number,
title,
description,
due_on,
state,
},
)
.await
}
MilestoneCommand::Delete { number, yes } => {
write::delete(cli_hostname, cli_repo, cli_profile, number, yes).await
}
}
}