From 92b80d6bb7adf1ae9399e166295ee49cb358addc Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 11 May 2025 13:20:15 +1200 Subject: [PATCH] list implemented --- src/command_registry.hpp | 1 + src/commands/edit.cpp | 9 +++++- src/commands/help.cpp | 60 ++++++++++++++++++++++++++++++++++------ src/commands/list.cpp | 9 +++++- src/main.cpp | 6 ++-- 5 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/command_registry.hpp b/src/command_registry.hpp index 338631f..5e341be 100644 --- a/src/command_registry.hpp +++ b/src/command_registry.hpp @@ -25,6 +25,7 @@ struct CommandInfo { int max_args = -1; // -1 = unlimited std::string help_usage; // install SERVER [SERVICE] std::string help_description; // Install/reinstall/update service(s). Safe/non-destructive. + std::string full_help; // detailed help for the command }; class CommandRegistry { diff --git a/src/commands/edit.cpp b/src/commands/edit.cpp index 8d2df34..0bf0a52 100644 --- a/src/commands/edit.cpp +++ b/src/commands/edit.cpp @@ -31,7 +31,14 @@ struct EditCommandRegister { 0, // min_args (after command) 2, // max_args (after command) "edit [SERVER] [SERVICE]", - "Edit dropshell, server or service configuration" + "Edit dropshell, server or service configuration", + // heredoc + R"( + Edit dropshell, server or service configuration. + edit edit the dropshell config. + edit edit the server config. + edit edit the service config. + )" }); } } edit_command_register; diff --git a/src/commands/help.cpp b/src/commands/help.cpp index 7232cd0..1bc2437 100644 --- a/src/commands/help.cpp +++ b/src/commands/help.cpp @@ -30,9 +30,15 @@ struct HelpCommandRegister { false, // hidden false, // requires_config 0, // min_args (after command) - 0, // max_args (after command) - "help", - "Show help for dropshell" + 1, // max_args (after command) + "help [COMMAND]", + "Show help for dropshell, or detailed help for a specific command.", + // heredoc + R"( + Show help for dropshell, or detailed help for a specific command. + If you want to see documentation, please visit the DropShell website: + https://dropshell.app + )" }); } } help_command_register; @@ -40,7 +46,10 @@ struct HelpCommandRegister { void help_autocomplete(const CommandContext& ctx) { if (ctx.args.size() == 1) { - std::cout << "help" << std::endl; + // list all commands + for (const auto& cmd : CommandRegistry::instance().list_primary_commands(false)) { + std::cout << cmd << std::endl; + } } return; } @@ -60,7 +69,42 @@ extern const std::string RELEASE_DATE; extern const std::string AUTHOR; extern const std::string LICENSE; + +int show_command_help(const std::string& cmd) { + const auto& cmd_info = CommandRegistry::instance().find_command(cmd); + if (!cmd_info) + { + std::cout << "Unknown command: " << cmd << std::endl; + return 1; + } + + std::cout << std::endl; + std::cout << "Usage: " << std::endl; + std::cout << " "; + print_left_aligned(cmd_info->help_usage, 30); + std::cout << cmd_info->help_description << std::endl; + + std::cout << std::endl; + + std::cout << " Equivalent names: "; + bool first = true; + for (const auto& name : cmd_info->names) { + if (!first) std::cout << ", "; + std::cout << name; + first = false; + } + std::cout << std::endl << std::endl; + + std::cout << cmd_info->full_help << std::endl << std::endl; + + return 0; +} + int help_handler(const CommandContext& ctx) { + + if (ctx.args.size() > 0) + return show_command_help(ctx.args[0]); + std::cout << std::endl; maketitle("DropShell version " + VERSION); std::cout << std::endl; @@ -71,16 +115,14 @@ int help_handler(const CommandContext& ctx) { show_command("help"); show_command("edit"); - - if (gConfig().is_config_set()) { + if (gConfig().is_config_set()) + { // show more! + show_command("list"); } - return 0; } - - // void show_command(const std::string& cmd) { // const auto& cmd_info = CommandRegistry::instance().find_command(cmd); // if (cmd_info) { diff --git a/src/commands/list.cpp b/src/commands/list.cpp index 613ab89..62d54b0 100644 --- a/src/commands/list.cpp +++ b/src/commands/list.cpp @@ -34,7 +34,14 @@ struct ListCommandRegister { 0, // min_args (after command) 2, // max_args (after command) "list [SERVER] [SERVICE]", - "List dropshell, server or service configuration" + "List server or service information and status", + // heredoc + R"( +List details for servers and services controller by dropshell. + list list all servers. + list server list all services for the given server. + list server service list the given service details on the given server. + )" }); } } list_command_register; diff --git a/src/main.cpp b/src/main.cpp index 4bb2d9d..9728ef5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,9 +63,9 @@ int main(int argc, char* argv[]) { if (arg_count < info->min_args || (info->max_args != -1 && arg_count > info->max_args)) { std::cerr << "Invalid number of arguments for command: " << cmd << std::endl; std::cerr << "Usage: " << std::endl; - std::cout << " " << info->help_usage - << std::string(' ', std::max(1, (int)(30 - info->help_usage.length()))) - << info->help_description << std::endl; + std::cout << " "; + print_left_aligned(info->help_usage,30); + std::cout << info->help_description << std::endl; return 1; } CommandContext ctx{args[0], cmd, std::vector(args.begin() + 2, args.end())};