#![allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Category {
Broker,
Cluster,
Benchmark,
Identity,
Monitoring,
Diagnostics,
Container,
Ui,
Meta,
}
impl Category {
pub fn title(self) -> &'static str {
match self {
Category::Broker => "Broker Commands",
Category::Cluster => "Cluster Commands",
Category::Benchmark => "Benchmark Commands",
Category::Identity => "Identity",
Category::Monitoring => "Monitoring",
Category::Diagnostics => "Diagnostics",
Category::Container => "Container Commands",
Category::Ui => "Interface",
Category::Meta => "General",
}
}
pub fn order() -> &'static [Category] {
&[
Category::Broker,
Category::Cluster,
Category::Benchmark,
Category::Identity,
Category::Monitoring,
Category::Diagnostics,
Category::Container,
Category::Ui,
Category::Meta,
]
}
}
#[derive(Debug, Clone, Copy)]
pub struct ArgSpec {
pub name: &'static str,
pub required: bool,
pub summary: &'static str,
}
impl ArgSpec {
pub const fn required(name: &'static str, summary: &'static str) -> Self {
ArgSpec {
name,
required: true,
summary,
}
}
pub const fn optional(name: &'static str, summary: &'static str) -> Self {
ArgSpec {
name,
required: false,
summary,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct CommandSpec {
pub name: &'static str,
pub aliases: &'static [&'static str],
pub args: &'static [ArgSpec],
pub summary: &'static str,
pub help_md: &'static str,
pub category: Category,
}
impl CommandSpec {
pub fn matches(&self, token: &str) -> bool {
self.name == token || self.aliases.contains(&token)
}
pub fn usage(&self) -> String {
let mut s = String::from(self.name);
for a in self.args {
if a.required {
s.push_str(&format!(" <{}>", a.name));
} else {
s.push_str(&format!(" [{}]", a.name));
}
}
s
}
}