use clap::{ArgMatches, Command as Cmd};
use super::output::{CliError, Outcome};
pub struct Tool {
pub name: &'static str,
pub verb: &'static str,
pub section: u8,
pub about: &'static str,
pub usage_exit: u8,
pub command: fn() -> Cmd,
pub run: fn(&ArgMatches) -> Result<Outcome, CliError>,
}
pub struct Family {
pub repo: &'static str,
pub crate_name: &'static str,
pub version: &'static str,
pub about: &'static str,
pub install_hints: &'static [&'static str],
pub tools: &'static [Tool],
}
impl Family {
pub fn by_name(&self, name: &str) -> Option<&Tool> {
self.tools.iter().find(|tool| tool.name == name)
}
pub fn by_word(&self, word: &str) -> Option<&Tool> {
self.tools
.iter()
.find(|tool| tool.verb == word || tool.name == word)
}
}