Skip to main content

ytcli/cli/
goal.rs

1//! Goal commands.
2
3use clap::Subcommand;
4
5use crate::cli::{Session, entity};
6use crate::exit::ExitCode;
7
8#[derive(Debug, Subcommand)]
9pub enum GoalCommand {
10    /// List goals.
11    #[command(long_about = crate::cli::help::md(crate::cli::help::GOAL_LIST))]
12    List {
13        /// Free-text search over names and descriptions.
14        #[arg(long, short = 'Q')]
15        query: Option<String>,
16        /// 1-based page number.
17        #[arg(long, default_value_t = 1)]
18        page: u32,
19    },
20    /// Show one goal.
21    #[command(long_about = crate::cli::help::md(crate::cli::help::GOAL_GET))]
22    Get { id: String },
23    /// Create a goal.
24    #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_CREATE))]
25    Create {
26        #[command(flatten)]
27        fields: entity::Fields,
28    },
29    /// Change the fields of one.
30    #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_UPDATE))]
31    Update {
32        /// The id `goal list` prints.
33        id: String,
34        #[command(flatten)]
35        fields: entity::Fields,
36    },
37    /// Delete one. Needs --yes, and nothing puts it back.
38    #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_DELETE))]
39    Delete {
40        /// The id `goal list` prints.
41        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}