This commit is contained in:
parent
62191cceed
commit
92b80d6bb7
@ -25,6 +25,7 @@ struct CommandInfo {
|
|||||||
int max_args = -1; // -1 = unlimited
|
int max_args = -1; // -1 = unlimited
|
||||||
std::string help_usage; // install SERVER [SERVICE]
|
std::string help_usage; // install SERVER [SERVICE]
|
||||||
std::string help_description; // Install/reinstall/update service(s). Safe/non-destructive.
|
std::string help_description; // Install/reinstall/update service(s). Safe/non-destructive.
|
||||||
|
std::string full_help; // detailed help for the command
|
||||||
};
|
};
|
||||||
|
|
||||||
class CommandRegistry {
|
class CommandRegistry {
|
||||||
|
@ -31,7 +31,14 @@ struct EditCommandRegister {
|
|||||||
0, // min_args (after command)
|
0, // min_args (after command)
|
||||||
2, // max_args (after command)
|
2, // max_args (after command)
|
||||||
"edit [SERVER] [SERVICE]",
|
"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;
|
} edit_command_register;
|
||||||
|
@ -30,9 +30,15 @@ struct HelpCommandRegister {
|
|||||||
false, // hidden
|
false, // hidden
|
||||||
false, // requires_config
|
false, // requires_config
|
||||||
0, // min_args (after command)
|
0, // min_args (after command)
|
||||||
0, // max_args (after command)
|
1, // max_args (after command)
|
||||||
"help",
|
"help [COMMAND]",
|
||||||
"Show help for dropshell"
|
"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;
|
} help_command_register;
|
||||||
@ -40,7 +46,10 @@ struct HelpCommandRegister {
|
|||||||
|
|
||||||
void help_autocomplete(const CommandContext& ctx) {
|
void help_autocomplete(const CommandContext& ctx) {
|
||||||
if (ctx.args.size() == 1) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -60,7 +69,42 @@ extern const std::string RELEASE_DATE;
|
|||||||
extern const std::string AUTHOR;
|
extern const std::string AUTHOR;
|
||||||
extern const std::string LICENSE;
|
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) {
|
int help_handler(const CommandContext& ctx) {
|
||||||
|
|
||||||
|
if (ctx.args.size() > 0)
|
||||||
|
return show_command_help(ctx.args[0]);
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
maketitle("DropShell version " + VERSION);
|
maketitle("DropShell version " + VERSION);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
@ -71,16 +115,14 @@ int help_handler(const CommandContext& ctx) {
|
|||||||
show_command("help");
|
show_command("help");
|
||||||
show_command("edit");
|
show_command("edit");
|
||||||
|
|
||||||
|
if (gConfig().is_config_set())
|
||||||
if (gConfig().is_config_set()) {
|
{
|
||||||
// show more!
|
// show more!
|
||||||
|
show_command("list");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// void show_command(const std::string& cmd) {
|
// void show_command(const std::string& cmd) {
|
||||||
// const auto& cmd_info = CommandRegistry::instance().find_command(cmd);
|
// const auto& cmd_info = CommandRegistry::instance().find_command(cmd);
|
||||||
// if (cmd_info) {
|
// if (cmd_info) {
|
||||||
|
@ -34,7 +34,14 @@ struct ListCommandRegister {
|
|||||||
0, // min_args (after command)
|
0, // min_args (after command)
|
||||||
2, // max_args (after command)
|
2, // max_args (after command)
|
||||||
"list [SERVER] [SERVICE]",
|
"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;
|
} list_command_register;
|
||||||
|
@ -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)) {
|
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 << "Invalid number of arguments for command: " << cmd << std::endl;
|
||||||
std::cerr << "Usage: " << std::endl;
|
std::cerr << "Usage: " << std::endl;
|
||||||
std::cout << " " << info->help_usage
|
std::cout << " ";
|
||||||
<< std::string(' ', std::max(1, (int)(30 - info->help_usage.length())))
|
print_left_aligned(info->help_usage,30);
|
||||||
<< info->help_description << std::endl;
|
std::cout << info->help_description << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
CommandContext ctx{args[0], cmd, std::vector<std::string>(args.begin() + 2, args.end())};
|
CommandContext ctx{args[0], cmd, std::vector<std::string>(args.begin() + 2, args.end())};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user