1use clap::Subcommand;
5
6use crate::cli::{Session, entity};
7use crate::exit::ExitCode;
8
9#[derive(Debug, Subcommand)]
10pub enum ProjectCommand {
11 #[command(long_about = crate::cli::help::md(crate::cli::help::PROJECT_LIST))]
13 List {
14 #[arg(long, short = 'Q')]
16 query: Option<String>,
17 #[arg(long, default_value_t = 1)]
19 page: u32,
20 },
21 #[command(long_about = crate::cli::help::md(crate::cli::help::PROJECT_GET))]
23 Get {
24 id: String,
26 },
27 #[command(long_about = crate::cli::help::md(crate::cli::help::PROJECT_PLACE))]
29 Place {
30 id: String,
32 #[arg(long, conflicts_with = "out")]
34 into: Option<String>,
35 #[arg(long, conflicts_with = "into")]
37 out: bool,
38 },
39 #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_CREATE))]
41 Create {
42 #[command(flatten)]
43 fields: entity::Fields,
44 },
45 #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_UPDATE))]
47 Update {
48 id: String,
50 #[command(flatten)]
51 fields: entity::Fields,
52 },
53 #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_DELETE))]
55 Delete {
56 id: String,
58 },
59}
60
61pub async fn run(command: &ProjectCommand, session: &Session) -> ExitCode {
62 match command {
63 ProjectCommand::List { query, page } => {
64 entity::list("project", query.as_deref(), *page, session).await
65 }
66 ProjectCommand::Get { id } => entity::get("project", id, session).await,
67 ProjectCommand::Place { id, into, out } => {
68 if into.is_none() && !*out {
69 return crate::cli::report(
70 &"say where: --into <portfolio>, or --out to remove it from one",
71 crate::exit::ExitCode::ConfirmationRequired,
72 );
73 }
74 entity::place("project", id, into.as_deref(), session).await
75 }
76 ProjectCommand::Create { fields } => entity::create("project", fields, session).await,
77 ProjectCommand::Update { id, fields } => {
78 entity::update("project", id, fields, session).await
79 }
80 ProjectCommand::Delete { id } => entity::remove("project", id, session).await,
81 }
82}