Skip to main content

release_kit/cli/
message.rs

1//! Arguments for `rk message`.
2
3use camino::Utf8PathBuf;
4use clap::{Args, ValueEnum};
5
6/// Judge a commit message, title, or body against the content guards.
7#[derive(Debug, Args)]
8pub struct MessageArgs {
9    /// The file holding the text, `-` or absent for stdin; pre-commit's
10    /// commit-msg stage passes the message file here.
11    pub file: Option<Utf8PathBuf>,
12
13    /// Exit 1 when any finding stands, instead of only reporting.
14    #[arg(long)]
15    pub check: bool,
16
17    /// Emit one JSON object on stdout instead of the human report.
18    #[arg(long)]
19    pub json: bool,
20
21    /// What the text is: a whole commit message, a title alone, or a
22    /// request body.
23    #[arg(long, value_enum, default_value_t = MessageKind::Commit)]
24    pub kind: MessageKind,
25
26    /// The repository whose ignore rules judge a referenced path.
27    #[arg(long, default_value = ".")]
28    pub target: Utf8PathBuf,
29
30    /// The request title a body belongs to, for the bot exemption.
31    #[arg(long)]
32    pub title: Option<String>,
33}
34
35/// The three text shapes the verb judges.
36#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
37pub enum MessageKind {
38    /// A whole commit message; its first line is the title.
39    Commit,
40    /// A title alone.
41    Title,
42    /// A request body; `--title` supplies its title.
43    Body,
44}
45
46impl MessageKind {
47    /// The kind's report name.
48    #[must_use]
49    pub const fn as_str(self) -> &'static str {
50        match self {
51            Self::Commit => "commit",
52            Self::Title => "title",
53            Self::Body => "body",
54        }
55    }
56}