Skip to content

Commit

Permalink
Improved help
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Aug 19, 2023
1 parent d76bada commit 3e1d899
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions gitcash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ impl CommandSuggester {
Self {
commands: commands
.iter()
.map(|command| (*command).into())
.collect::<Vec<&'static str>>(),
.map(|command| command.command())
.collect::<Vec<_>>(),
}
}
}

impl Autocomplete for CommandSuggester {
fn get_suggestions(&mut self, input: &str) -> Result<Vec<String>, inquire::CustomUserError> {
if input.is_empty() {
return Ok(vec![]);
}
Ok(self
.commands
.iter()
Expand All @@ -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 {
Expand Down Expand Up @@ -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(_) => {}
Expand Down

0 comments on commit 3e1d899

Please sign in to comment.