1use std::fmt;
9
10use clap::ValueEnum;
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ValueEnum)]
14#[value(rename_all = "kebab-case")]
15pub enum GateId {
16 AdrCitesALiveRule,
18 AdrFilenameShape,
20 AdrWordCap,
22 AgentsDigestSize,
24 ChapterSizeCap,
26 ComparisonDatedTables,
28 ComparisonEscapedPipes,
30 ComparisonLegend,
32 ComparisonOneReferencePerCell,
34 ComparisonVerdictWord,
36 GateMessageCitesARule,
38 InstanceManifest,
40 KiBugzillaReportWidth,
42 KiFilenameShape,
44 KiFiling,
46 KiMechanismWalkthrough,
48 KiReportBody,
50 KiRetireWhen,
52 KiState,
54 NoPersonalPath,
56 NoSelfNarration,
58 ProseStaysUnwrapped,
60 SpecRequirementParts,
62 SpecRuleIdUnique,
64 SpecSizeCap,
66 SpecVerifyHooksExist,
68 SuppressionNamesItsCase,
70}
71
72impl GateId {
73 pub const ALL: &'static [Self] = &[
75 Self::AdrCitesALiveRule,
76 Self::AdrFilenameShape,
77 Self::AdrWordCap,
78 Self::AgentsDigestSize,
79 Self::ChapterSizeCap,
80 Self::ComparisonDatedTables,
81 Self::ComparisonEscapedPipes,
82 Self::ComparisonLegend,
83 Self::ComparisonOneReferencePerCell,
84 Self::ComparisonVerdictWord,
85 Self::GateMessageCitesARule,
86 Self::InstanceManifest,
87 Self::KiBugzillaReportWidth,
88 Self::KiFilenameShape,
89 Self::KiFiling,
90 Self::KiMechanismWalkthrough,
91 Self::KiReportBody,
92 Self::KiRetireWhen,
93 Self::KiState,
94 Self::NoPersonalPath,
95 Self::NoSelfNarration,
96 Self::ProseStaysUnwrapped,
97 Self::SpecRequirementParts,
98 Self::SpecRuleIdUnique,
99 Self::SpecSizeCap,
100 Self::SpecVerifyHooksExist,
101 Self::SuppressionNamesItsCase,
102 ];
103
104 #[must_use]
106 pub const fn as_str(self) -> &'static str {
107 match self {
108 Self::AdrCitesALiveRule => "adr-cites-a-live-rule",
109 Self::AdrFilenameShape => "adr-filename-shape",
110 Self::AdrWordCap => "adr-word-cap",
111 Self::AgentsDigestSize => "agents-digest-size",
112 Self::ChapterSizeCap => "chapter-size-cap",
113 Self::ComparisonDatedTables => "comparison-dated-tables",
114 Self::ComparisonEscapedPipes => "comparison-escaped-pipes",
115 Self::ComparisonLegend => "comparison-legend",
116 Self::ComparisonOneReferencePerCell => "comparison-one-reference-per-cell",
117 Self::ComparisonVerdictWord => "comparison-verdict-word",
118 Self::GateMessageCitesARule => "gate-message-cites-a-rule",
119 Self::InstanceManifest => "instance-manifest",
120 Self::KiBugzillaReportWidth => "ki-bugzilla-report-width",
121 Self::KiFilenameShape => "ki-filename-shape",
122 Self::KiFiling => "ki-filing",
123 Self::KiMechanismWalkthrough => "ki-mechanism-walkthrough",
124 Self::KiReportBody => "ki-report-body",
125 Self::KiRetireWhen => "ki-retire-when",
126 Self::KiState => "ki-state",
127 Self::NoPersonalPath => "no-personal-path",
128 Self::NoSelfNarration => "no-self-narration",
129 Self::ProseStaysUnwrapped => "prose-stays-unwrapped",
130 Self::SpecRequirementParts => "spec-requirement-parts",
131 Self::SpecRuleIdUnique => "spec-rule-id-unique",
132 Self::SpecSizeCap => "spec-size-cap",
133 Self::SpecVerifyHooksExist => "spec-verify-hooks-exist",
134 Self::SuppressionNamesItsCase => "suppression-names-its-case",
135 }
136 }
137}
138
139impl std::str::FromStr for GateId {
140 type Err = String;
141
142 fn from_str(s: &str) -> Result<Self, Self::Err> {
143 Self::ALL
144 .iter()
145 .copied()
146 .find(|gate| gate.as_str() == s)
147 .ok_or_else(|| format!("unknown gate: {s}"))
148 }
149}
150
151impl fmt::Display for GateId {
152 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153 f.write_str(self.as_str())
154 }
155}
156
157#[cfg(test)]
158mod tests {
159 use super::*;
160
161 #[test]
162 fn all_lists_every_variant_once() {
163 let mut seen = std::collections::BTreeSet::new();
164 for gate in GateId::ALL {
165 assert!(seen.insert(gate.as_str()), "{gate} is duplicated");
166 }
167 assert_eq!(GateId::ALL.len(), 27);
168 }
169
170 #[test]
171 fn clap_value_matches_as_str() {
172 for gate in GateId::ALL {
173 let value = gate.to_possible_value().unwrap();
174 assert_eq!(value.get_name(), gate.as_str());
175 }
176 }
177}