Skip to main content

ytcli/cli/
project.rs

1//! Project commands. Projects group issues across queues; portfolios sit above
2//! them and are out of scope for v1.
3
4use clap::Subcommand;
5
6use crate::cli::{Session, entity};
7use crate::exit::ExitCode;
8
9#[derive(Debug, Subcommand)]
10pub enum ProjectCommand {
11    /// List projects.
12    #[command(long_about = crate::cli::help::md(crate::cli::help::PROJECT_LIST))]
13    List {
14        /// Free-text search over names and descriptions.
15        #[arg(long, short = 'Q')]
16        query: Option<String>,
17        /// 1-based page number.
18        #[arg(long, default_value_t = 1)]
19        page: u32,
20    },
21    /// Show one project.
22    #[command(long_about = crate::cli::help::md(crate::cli::help::PROJECT_GET))]
23    Get {
24        /// Project id as returned by `project list`, not an issue key.
25        id: String,
26    },
27    /// Put it inside a portfolio, or take it out of one.
28    #[command(long_about = crate::cli::help::md(crate::cli::help::PROJECT_PLACE))]
29    Place {
30        /// The project to move, by the id `project list` prints.
31        id: String,
32        /// Portfolio to put it in.
33        #[arg(long, conflicts_with = "out")]
34        into: Option<String>,
35        /// Take it out of whichever portfolio it is in.
36        #[arg(long, conflicts_with = "into")]
37        out: bool,
38    },
39    /// Create a project.
40    #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_CREATE))]
41    Create {
42        #[command(flatten)]
43        fields: entity::Fields,
44    },
45    /// Change the fields of one.
46    #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_UPDATE))]
47    Update {
48        /// The id `project list` prints.
49        id: String,
50        #[command(flatten)]
51        fields: entity::Fields,
52    },
53    /// Delete one. Needs --yes, and nothing puts it back.
54    #[command(long_about = crate::cli::help::md(crate::cli::help::ENTITY_DELETE))]
55    Delete {
56        /// The id `project list` prints.
57        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}