1use clap::Subcommand;
5
6use crate::cli::{Session, entity};
7use crate::exit::ExitCode;
8
9#[derive(Debug, Subcommand)]
10pub enum PortfolioCommand {
11 #[command(long_about = crate::cli::help::md(crate::cli::help::PORTFOLIO_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::PORTFOLIO_GET))]
23 Get {
24 id: String,
26 },
27 #[command(long_about = crate::cli::help::md(crate::cli::help::PORTFOLIO_CONTENTS))]
29 Contents {
30 id: String,
32 #[arg(long, default_value_t = 1)]
34 page: u32,
35 },
36 #[command(long_about = crate::cli::help::md(crate::cli::help::PORTFOLIO_PLACE))]
38 Place {
39 id: String,
41 #[arg(long, conflicts_with = "out")]
43 into: Option<String>,
44 #[arg(long, conflicts_with = "into")]
46 out: bool,
47 },
48 #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_CREATE))]
50 Create {
51 #[command(flatten)]
52 fields: entity::Fields,
53 },
54 #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_UPDATE))]
56 Update {
57 id: String,
59 #[command(flatten)]
60 fields: entity::Fields,
61 },
62 #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_DELETE))]
64 Delete {
65 id: String,
67 },
68}
69
70pub async fn run(command: &PortfolioCommand, session: &Session) -> ExitCode {
71 match command {
72 PortfolioCommand::List { query, page } => {
73 entity::list("portfolio", query.as_deref(), *page, session).await
74 }
75 PortfolioCommand::Get { id } => entity::get("portfolio", id, session).await,
76 PortfolioCommand::Contents { id, page } => entity::contents(id, *page, session).await,
77 PortfolioCommand::Place { id, into, out } => {
78 if into.is_none() && !*out {
79 return crate::cli::report(
80 &"say where: --into <portfolio>, or --out to remove it from one",
81 crate::exit::ExitCode::ConfirmationRequired,
82 );
83 }
84 entity::place("portfolio", id, into.as_deref(), session).await
85 }
86 PortfolioCommand::Create { fields } => entity::create("portfolio", fields, session).await,
87 PortfolioCommand::Update { id, fields } => {
88 entity::update("portfolio", id, fields, session).await
89 }
90 PortfolioCommand::Delete { id } => entity::remove("portfolio", id, session).await,
91 }
92}