arkham/src/command.rs

40 lines
784 B
Rust

use crate::{
context::Context,
opt::{self, Opt},
vox, App,
};
pub type Handler = fn(&App, &Context, &[String]);
pub struct Command {
pub name: String,
pub commands: Vec<Command>,
pub handler: Option<Handler>,
pub opts: Vec<opt::Opt>,
}
impl Command {
pub fn new<T: Into<String>>(name: T) -> Self {
Command {
name: name.into(),
commands: vec![],
handler: None,
opts: vec![],
}
}
pub fn handler(mut self, f: Handler) -> Self {
self.handler = Some(f);
self
}
pub fn opt(mut self, opt: Opt) -> Self {
self.opts.push(opt);
self
}
}
pub fn help(app: &App, _ctx: &Context, _args: &[String]) {
vox::print(app.application_header());
}