Update source/src/commands/create-service.cpp
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 26s
Build-Test-Publish / build (linux/arm64) (push) Successful in 56s

This commit is contained in:
j
2026-01-15 10:25:23 +13:00
parent 22e2397624
commit cbae2db05c

View File

@@ -30,14 +30,15 @@ namespace dropshell
false, // hidden false, // hidden
true, // requires_config true, // requires_config
true, // requires_install true, // requires_install
3, // min_args (after command) 2, // min_args (after command)
3, // max_args (after command) 3, // max_args (after command)
"create-service SERVER SERVICE TEMPLATE", "create-service SERVER TEMPLATE [SERVICE]",
"Create a service on a server.", "Create a service on a server.",
// heredoc // heredoc
R"( R"(
Create a service on a server. Create a service on a server.
create-service SERVER SERVICE TEMPLATE create the given service on the given server. create-service SERVER TEMPLATE [SERVICE] create a service on the given server.
SERVICE defaults to TEMPLATE name if not specified.
)"}); )"});
} }
} create_service_command_register; } create_service_command_register;
@@ -45,24 +46,34 @@ namespace dropshell
int create_service_handler(const CommandContext &ctx) int create_service_handler(const CommandContext &ctx)
{ {
std::string server = safearg(ctx.args, 0); std::string server = safearg(ctx.args, 0);
std::string service = safearg(ctx.args, 1); std::string template_name = safearg(ctx.args, 1);
std::string template_name = safearg(ctx.args, 2); std::string service = safearg(ctx.args, 2);
// Default service name to template name if not specified
if (service.empty())
service = template_name;
return shared_commands::create_service(server, template_name, service) ? 0 : 1; return shared_commands::create_service(server, template_name, service) ? 0 : 1;
} }
void create_service_autocomplete(const CommandContext &ctx) void create_service_autocomplete(const CommandContext &ctx)
{ {
if (ctx.args.size() < 2) if (ctx.args.size() == 0)
{
// First arg: server name
shared_commands::std_autocomplete(ctx); shared_commands::std_autocomplete(ctx);
else }
{ else if (ctx.args.size() == 1)
if (ctx.args.size() == 2)
{ {
// Second arg: template name
std::set<std::string> templates = gTemplateManager().get_template_list(); std::set<std::string> templates = gTemplateManager().get_template_list();
for (const auto &template_name : templates) for (const auto &template_name : templates)
rawout << template_name << std::endl; rawout << template_name << std::endl;
} }
else if (ctx.args.size() == 2)
{
// Third arg: service name - suggest template name as default
rawout << ctx.args[1] << std::endl;
} }
} }