Skip to main content

release_kit/cli/
profile_flags.rs

1//! The flags every verb that resolves a target configuration takes: the
2//! project profile and the Git workflow, as `rk init`, `rk adopt`,
3//! `rk stage`, and `rk profile` read them.
4//!
5//! The canonical names are the long forms below. Three older spellings
6//! stay as hidden aliases, so an existing command line keeps working:
7//! `--tech` for one `--technology`, `--style` for `--release-style`, and
8//! `--workflow` for `--checkout-mode`, whose older values `worktree` and
9//! `branches` the parser still reads.
10
11use clap::Args;
12
13/// The profile and Git workflow answers an invocation states.
14#[derive(Debug, Clone, Default, Args)]
15pub struct ProfileFlags {
16    /// A technology present in the project; repeat it for several. A
17    /// supplied list replaces the configured one whole. Defaults to
18    /// detection from the version files.
19    #[arg(long = "technology", alias = "tech", value_name = "NAME")]
20    pub technology: Vec<String>,
21
22    /// The forge hosting the project: github or gitlab. Defaults to
23    /// detection from the target's git remote; a project with no forge
24    /// resolves to none.
25    #[arg(long)]
26    pub forge: Option<String>,
27
28    /// The project path on the forge, substituted into the rendered files
29    /// and recorded as the landing parameter. Defaults to detection from
30    /// the target's git remote.
31    #[arg(long)]
32    pub repo: Option<String>,
33
34    /// The release intent: automatic, where release-kit drives the
35    /// release; external, where the project releases through a process
36    /// release-kit does not drive; or none. Defaults to the observation's
37    /// proposal: automatic with the one release-bearing technology, none
38    /// where there is none.
39    #[arg(long, value_name = "MODE")]
40    pub release_mode: Option<String>,
41
42    /// The technology that states the version and takes the bot, for an
43    /// automatic release. Required where more than one release-bearing
44    /// technology is present.
45    #[arg(long, value_name = "NAME")]
46    pub release_driver: Option<String>,
47
48    /// The release style of an automatic release: trunk (the bot's
49    /// request carries auto-merge from creation) or lines (every request
50    /// waits for a human's merge).
51    #[arg(long, alias = "style", value_name = "STYLE")]
52    pub release_style: Option<String>,
53
54    /// The one permanent branch. Defaults to the configuration, the
55    /// record, and then master.
56    #[arg(long, value_name = "BRANCH")]
57    pub trunk: Option<String>,
58
59    /// Where a topic branch opens: linked-worktree (every code-changing
60    /// branch in its own linked worktree, the main checkout commits
61    /// nothing) or main-worktree (the original working tree switches to
62    /// it). Recorded as a Git workflow parameter and rendered into the
63    /// landed blocks.
64    #[arg(long, alias = "workflow", value_name = "MODE")]
65    pub checkout_mode: Option<String>,
66}
67
68impl ProfileFlags {
69    /// The parsed answers, as the resolution takes them.
70    ///
71    /// # Errors
72    ///
73    /// Returns [`crate::error::RkError::Usage`] for a value outside its
74    /// vocabulary.
75    pub fn inputs(&self) -> Result<crate::profile::Inputs<'_>, crate::error::RkError> {
76        use crate::landing::{CheckoutMode, Style};
77        use crate::profile::ReleaseMode;
78        Ok(crate::profile::Inputs {
79            technologies: &self.technology,
80            forge: self.forge.as_deref(),
81            repo: self.repo.as_deref(),
82            release_mode: self
83                .release_mode
84                .as_deref()
85                .map(ReleaseMode::parse)
86                .transpose()?,
87            release_driver: self.release_driver.as_deref(),
88            style: self
89                .release_style
90                .as_deref()
91                .map(Style::parse)
92                .transpose()?,
93            trunk: self.trunk.as_deref(),
94            checkout_mode: self
95                .checkout_mode
96                .as_deref()
97                .map(CheckoutMode::parse)
98                .transpose()?,
99            ..crate::profile::Inputs::default()
100        })
101    }
102}