use clap::{Args, Subcommand};
mod due_date;
mod read;
mod write;
#[derive(Args)]
pub struct MilestoneArgs {
#[command(subcommand)]
pub command: MilestoneCommand,
}
#[derive(Subcommand)]
pub enum MilestoneCommand {
List {
#[arg(
long,
short,
default_value = "open",
value_parser = ["open", "closed", "all"],
ignore_case = true
)]
state: String,
#[arg(long)]
json: bool,
},
View {
number: u64,
},
Create {
title: Option<String>,
#[arg(long, short)]
description: Option<String>,
#[arg(long = "due-on")]
due_on: Option<String>,
},
Edit {
number: u64,
#[arg(long, short)]
title: Option<String>,
#[arg(long, short)]
description: Option<String>,
#[arg(long = "due-on")]
due_on: Option<String>,
#[arg(long, short, value_parser = ["open", "closed"], ignore_case = true)]
state: Option<String>,
},
Delete {
number: u64,
#[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
}
}
}