1use clap::Subcommand;
4
5use crate::cli::{Session, entity};
6use crate::exit::ExitCode;
7
8#[derive(Debug, Subcommand)]
9pub enum GoalCommand {
10 #[command(long_about = crate::cli::help::md(crate::cli::help::GOAL_LIST))]
12 List {
13 #[arg(long, short = 'Q')]
15 query: Option<String>,
16 #[arg(long, default_value_t = 1)]
18 page: u32,
19 },
20 #[command(long_about = crate::cli::help::md(crate::cli::help::GOAL_GET))]
22 Get { id: String },
23 #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_CREATE))]
25 Create {
26 #[command(flatten)]
27 fields: entity::Fields,
28 },
29 #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_UPDATE))]
31 Update {
32 id: String,
34 #[command(flatten)]
35 fields: entity::Fields,
36 },
37 #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_DELETE))]
39 Delete {
40 id: String,
42 },
43}
44
45pub async fn run(command: &GoalCommand, session: &Session) -> ExitCode {
46 match command {
47 GoalCommand::List { query, page } => {
48 entity::list("goal", query.as_deref(), *page, session).await
49 }
50 GoalCommand::Get { id } => entity::get("goal", id, session).await,
51 GoalCommand::Create { fields } => entity::create("goal", fields, session).await,
52 GoalCommand::Update { id, fields } => entity::update("goal", id, fields, session).await,
53 GoalCommand::Delete { id } => entity::remove("goal", id, session).await,
54 }
55}