use clap::Subcommand;
use crate::cli::{Session, entity};
use crate::exit::ExitCode;
#[derive(Debug, Subcommand)]
pub enum ProjectCommand {
#[command(long_about = crate::cli::help::md(crate::cli::help::PROJECT_LIST))]
List {
#[arg(long, short = 'Q')]
query: Option<String>,
#[arg(long, default_value_t = 1)]
page: u32,
},
#[command(long_about = crate::cli::help::md(crate::cli::help::PROJECT_GET))]
Get {
id: String,
},
#[command(long_about = crate::cli::help::md(crate::cli::help::PROJECT_PLACE))]
Place {
id: String,
#[arg(long, conflicts_with = "out")]
into: Option<String>,
#[arg(long, conflicts_with = "into")]
out: bool,
},
#[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_CREATE))]
Create {
#[command(flatten)]
fields: entity::Fields,
},
#[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_UPDATE))]
Update {
id: String,
#[command(flatten)]
fields: entity::Fields,
},
#[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_DELETE))]
Delete {
id: String,
},
}
pub async fn run(command: &ProjectCommand, session: &Session) -> ExitCode {
match command {
ProjectCommand::List { query, page } => {
entity::list("project", query.as_deref(), *page, session).await
}
ProjectCommand::Get { id } => entity::get("project", id, session).await,
ProjectCommand::Place { id, into, out } => {
if into.is_none() && !*out {
return crate::cli::report(
&"say where: --into <portfolio>, or --out to remove it from one",
crate::exit::ExitCode::ConfirmationRequired,
);
}
entity::place("project", id, into.as_deref(), session).await
}
ProjectCommand::Create { fields } => entity::create("project", fields, session).await,
ProjectCommand::Update { id, fields } => {
entity::update("project", id, fields, session).await
}
ProjectCommand::Delete { id } => entity::remove("project", id, session).await,
}
}