1macro_rules! standard_commands {
24 ( $( $(#[$attr:meta])* $variant:ident => $signal:literal / $subcommand:literal ),* $(,)? ) => {
25 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31 pub enum StandardCommand {
32 $( $(#[$attr])* $variant, )*
33 }
34
35 impl StandardCommand {
36 pub const fn signal(self) -> &'static str {
39 match self {
40 $( Self::$variant => $signal, )*
41 }
42 }
43
44 pub const fn subcommand(self) -> &'static str {
47 match self {
48 $( Self::$variant => $subcommand, )*
49 }
50 }
51 }
52 };
53}
54
55standard_commands! {
56 MetricQuery => "metric" / "query",
58 MetricList => "metric" / "list",
60 MetricInfo => "metric" / "info",
62 MetricLabels => "metric" / "labels",
64 MetricLabelValues => "metric" / "label-values",
66 MetricSeries => "metric" / "series",
68 LogSearch => "log" / "search",
70 TraceSearch => "trace" / "search",
72 TraceGet => "trace" / "get",
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn signal_and_subcommand_round_trip() {
82 assert_eq!(StandardCommand::MetricQuery.signal(), "metric");
83 assert_eq!(StandardCommand::MetricQuery.subcommand(), "query");
84 assert_eq!(StandardCommand::MetricList.signal(), "metric");
85 assert_eq!(StandardCommand::MetricList.subcommand(), "list");
86 assert_eq!(StandardCommand::MetricInfo.signal(), "metric");
87 assert_eq!(StandardCommand::MetricInfo.subcommand(), "info");
88 assert_eq!(StandardCommand::MetricLabels.signal(), "metric");
89 assert_eq!(StandardCommand::MetricLabels.subcommand(), "labels");
90 assert_eq!(StandardCommand::MetricLabelValues.signal(), "metric");
91 assert_eq!(
92 StandardCommand::MetricLabelValues.subcommand(),
93 "label-values"
94 );
95 assert_eq!(StandardCommand::MetricSeries.signal(), "metric");
96 assert_eq!(StandardCommand::MetricSeries.subcommand(), "series");
97 assert_eq!(StandardCommand::LogSearch.signal(), "log");
98 assert_eq!(StandardCommand::LogSearch.subcommand(), "search");
99 assert_eq!(StandardCommand::TraceSearch.signal(), "trace");
100 assert_eq!(StandardCommand::TraceSearch.subcommand(), "search");
101 assert_eq!(StandardCommand::TraceGet.signal(), "trace");
102 assert_eq!(StandardCommand::TraceGet.subcommand(), "get");
103 }
104}