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