Skip to main content

add_help_handler

Function add_help_handler 

Source
pub fn add_help_handler<'a>(names: Vec<&'a str>, e: &mut Engine<'a>)
Examples found in repository?
examples/demo.rs (line 128)
107fn main() {
108    let mut ap = ArgsP::new();
109    let mut engine = Engine::new(&mut ap, "TAP DEMO — lightweight CLI parsing".to_string());
110
111    commands! {
112        engine;
113        "greet"   => greet_handler   { optional: ["name"],         docs: "Greet someone. Flag: --loud" }
114        "add"     => add_handler     { required: ["a", "b"],       docs: "Sum two numbers" }
115        "serve"   => serve_handler   { optional: ["host", "port"], docs: "Start a server. Flags: --verbose, --tls=on|off|auto, --workers=N" }
116        "report"  => report_handler  {                             docs: "Render templates and JSON" }
117        "version" => version_handler {                             docs: "Print version" }
118    }
119
120    subcommands! {
121        engine;
122        "echo" | "say" => echo_handler {
123            unlimited: true,
124            docs: "Echo back all arguments (subcommand)."
125        }
126    }
127
128    add_help_handler(vec!["help", "-h"], &mut engine);
129
130    if let Err(e) = engine.main() {
131        cprintln!("[?RD][error][?RT] {}", e);
132        std::process::exit(1);
133    }
134}