From 8774468d48669f24336eb3aee4fcded34296bb43 Mon Sep 17 00:00:00 2001 From: user0-07161 Date: Fri, 21 Mar 2025 22:16:47 +0100 Subject: [PATCH] feat: list commands when no command is called --- shell/src/ash.rs | 1 - src/boxcmd.rs | 5 ++++- utils/src/registry.rs | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/shell/src/ash.rs b/shell/src/ash.rs index d246d62..89f6010 100644 --- a/shell/src/ash.rs +++ b/shell/src/ash.rs @@ -3,7 +3,6 @@ use std::env; use std::process::Command as stdCommand; use std::io::{self, Write, ErrorKind}; use std::path::Path; -use std::fmt; pub struct Ash; diff --git a/src/boxcmd.rs b/src/boxcmd.rs index 1372760..c8e0f8d 100644 --- a/src/boxcmd.rs +++ b/src/boxcmd.rs @@ -13,6 +13,9 @@ impl Command for Boxcmd { registry.execute(cmd); return; } - println!("No command provided."); + println!( + "No command provided. Included commands:\n{}", + registry.list().join(", ") + ); } } diff --git a/utils/src/registry.rs b/utils/src/registry.rs index 9eff13c..4ee4e0d 100644 --- a/utils/src/registry.rs +++ b/utils/src/registry.rs @@ -16,6 +16,14 @@ impl CommandRegistry { self.commands.insert(name.to_string(), command); } + pub fn list(&self) -> Vec { + let mut bufvec = Vec::new(); + for (key, _value) in self.commands.iter() { + bufvec.push(String::from(key)) + } + bufvec + } + pub fn get(&self, name: &str) -> Option<&Box> { self.commands.get(name) }