list implemented
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 20s

This commit is contained in:
Your Name 2025-05-11 13:20:15 +12:00
parent 62191cceed
commit 92b80d6bb7
5 changed files with 71 additions and 14 deletions

View File

@ -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 {

View File

@ -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 <server> edit the server config.
edit <server> <service> edit the service config.
)"
});
}
} edit_command_register;

View File

@ -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) {

View File

@ -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;

View File

@ -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<std::string>(args.begin() + 2, args.end())};