From 3e1d899faff2608a95cd0fd045a746ea280ef970 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Fri, 18 Aug 2023 19:06:04 +0200 Subject: [PATCH] Improved help --- gitcash/src/main.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/gitcash/src/main.rs b/gitcash/src/main.rs index 9becfbe..275a9b2 100644 --- a/gitcash/src/main.rs +++ b/gitcash/src/main.rs @@ -45,14 +45,17 @@ impl CommandSuggester { Self { commands: commands .iter() - .map(|command| (*command).into()) - .collect::>(), + .map(|command| command.command()) + .collect::>(), } } } impl Autocomplete for CommandSuggester { fn get_suggestions(&mut self, input: &str) -> Result, inquire::CustomUserError> { + if input.is_empty() { + return Ok(vec![]); + } Ok(self .commands .iter() @@ -76,13 +79,20 @@ enum CliCommand { Help, } -impl Into<&'static str> for CliCommand { - fn into(self) -> &'static str { +impl CliCommand { + fn command(&self) -> &'static str { match self { CliCommand::AddUser => "adduser", CliCommand::Help => "help", } } + + fn description(&self) -> &'static str { + match self { + CliCommand::AddUser => "Add a new user", + CliCommand::Help => "Show this help", + } + } } impl TryFrom<&str> for CliCommand { @@ -217,7 +227,10 @@ fn handle_cli_input(repo: &mut Repo, config: &Config) -> anyhow::Result<()> { return Ok(()); } Ok(CliCommand::Help) => { - println!("Help"); + println!("Available commands:"); + for command in COMMANDS { + println!("- {}: {}", command.command(), command.description()); + } return Ok(()); } Err(_) => {}