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 SimpleEnglish,
72 TrackingRegistry,
74}
75
76impl GateId {
77 pub const ALL: &'static [Self] = &[
79 Self::AdrCitesALiveRule,
80 Self::AdrFilenameShape,
81 Self::AdrWordCap,
82 Self::AgentsDigestSize,
83 Self::ChapterSizeCap,
84 Self::ComparisonDatedTables,
85 Self::ComparisonEscapedPipes,
86 Self::ComparisonLegend,
87 Self::ComparisonOneReferencePerCell,
88 Self::ComparisonVerdictWord,
89 Self::GateMessageCitesARule,
90 Self::InstanceManifest,
91 Self::KiBugzillaReportWidth,
92 Self::KiFilenameShape,
93 Self::KiFiling,
94 Self::KiMechanismWalkthrough,
95 Self::KiReportBody,
96 Self::KiRetireWhen,
97 Self::KiState,
98 Self::NoPersonalPath,
99 Self::NoSelfNarration,
100 Self::ProseStaysUnwrapped,
101 Self::SpecRequirementParts,
102 Self::SpecRuleIdUnique,
103 Self::SpecSizeCap,
104 Self::SpecVerifyHooksExist,
105 Self::SuppressionNamesItsCase,
106 Self::SimpleEnglish,
107 Self::TrackingRegistry,
108 ];
109
110 #[must_use]
112 pub const fn as_str(self) -> &'static str {
113 match self {
114 Self::AdrCitesALiveRule => "adr-cites-a-live-rule",
115 Self::AdrFilenameShape => "adr-filename-shape",
116 Self::AdrWordCap => "adr-word-cap",
117 Self::AgentsDigestSize => "agents-digest-size",
118 Self::ChapterSizeCap => "chapter-size-cap",
119 Self::ComparisonDatedTables => "comparison-dated-tables",
120 Self::ComparisonEscapedPipes => "comparison-escaped-pipes",
121 Self::ComparisonLegend => "comparison-legend",
122 Self::ComparisonOneReferencePerCell => "comparison-one-reference-per-cell",
123 Self::ComparisonVerdictWord => "comparison-verdict-word",
124 Self::GateMessageCitesARule => "gate-message-cites-a-rule",
125 Self::InstanceManifest => "instance-manifest",
126 Self::KiBugzillaReportWidth => "ki-bugzilla-report-width",
127 Self::KiFilenameShape => "ki-filename-shape",
128 Self::KiFiling => "ki-filing",
129 Self::KiMechanismWalkthrough => "ki-mechanism-walkthrough",
130 Self::KiReportBody => "ki-report-body",
131 Self::KiRetireWhen => "ki-retire-when",
132 Self::KiState => "ki-state",
133 Self::NoPersonalPath => "no-personal-path",
134 Self::NoSelfNarration => "no-self-narration",
135 Self::ProseStaysUnwrapped => "prose-stays-unwrapped",
136 Self::SpecRequirementParts => "spec-requirement-parts",
137 Self::SpecRuleIdUnique => "spec-rule-id-unique",
138 Self::SpecSizeCap => "spec-size-cap",
139 Self::SpecVerifyHooksExist => "spec-verify-hooks-exist",
140 Self::SuppressionNamesItsCase => "suppression-names-its-case",
141 Self::SimpleEnglish => "simple-english",
142 Self::TrackingRegistry => "tracking-registry",
143 }
144 }
145}
146
147impl std::str::FromStr for GateId {
148 type Err = String;
149
150 fn from_str(s: &str) -> Result<Self, Self::Err> {
151 Self::ALL
152 .iter()
153 .copied()
154 .find(|gate| gate.as_str() == s)
155 .ok_or_else(|| format!("unknown gate: {s}"))
156 }
157}
158
159impl fmt::Display for GateId {
160 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
161 f.write_str(self.as_str())
162 }
163}
164
165#[cfg(test)]
166mod tests {
167 use super::*;
168
169 #[test]
170 fn all_lists_every_variant_once() {
171 let mut seen = std::collections::BTreeSet::new();
172 for gate in GateId::ALL {
173 assert!(seen.insert(gate.as_str()), "{gate} is duplicated");
174 }
175 assert_eq!(GateId::ALL.len(), 29);
176 }
177
178 #[test]
179 fn clap_value_matches_as_str() {
180 for gate in GateId::ALL {
181 let value = gate.to_possible_value().unwrap();
182 assert_eq!(value.get_name(), gate.as_str());
183 }
184 }
185}