src/cli.rs: add insert_help() method
This commit is contained in:
parent
1201abcffa
commit
2b691daf6f
|
@ -32,7 +32,7 @@ fn command_map() -> CliCommandMap {
|
|||
let cmd_def = CliCommandMap::new()
|
||||
.insert("ls", CliCommand::new(&API_METHOD_TEST_COMMAND).into())
|
||||
.insert("test", CliCommand::new(&API_METHOD_TEST_COMMAND).into())
|
||||
.insert("help", help_command_def().into());
|
||||
.insert_help();
|
||||
|
||||
cmd_def
|
||||
}
|
||||
|
@ -53,12 +53,10 @@ fn main() -> Result<(), Error> {
|
|||
|
||||
while let Ok(line) = rl.readline("# prompt: ") {
|
||||
let helper = rl.helper().unwrap();
|
||||
// readline already handles tabs, so here we only split on spaces
|
||||
|
||||
let args = shellword_split(&line)?;
|
||||
|
||||
let def = helper.cmd_def();
|
||||
|
||||
handle_command(def, "", args);
|
||||
handle_command(helper.cmd_def(), "", args);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -73,6 +73,11 @@ impl CliCommandMap {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn insert_help(mut self) -> Self {
|
||||
self.commands.insert(String::from("help"), help_command_def().into());
|
||||
self
|
||||
}
|
||||
|
||||
fn find_command(&self, name: &str) -> Option<&CommandLineInterface> {
|
||||
|
||||
if let Some(sub_cmd) = self.commands.get(name) {
|
||||
|
|
Loading…
Reference in New Issue