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
true, // requires_config
true, // requires_install
3, // min_args (after command)
2, // min_args (after command)
3, // max_args (after command)
"create-service SERVER SERVICE TEMPLATE",
"create-service SERVER TEMPLATE [SERVICE]",
"Create a service on a server.",
// heredoc
R"(
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;
@@ -45,24 +46,34 @@ namespace dropshell
int create_service_handler(const CommandContext &ctx)
{
std::string server = safearg(ctx.args, 0);
std::string service = safearg(ctx.args, 1);
std::string template_name = safearg(ctx.args, 2);
std::string template_name = safearg(ctx.args, 1);
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;
}
void create_service_autocomplete(const CommandContext &ctx)
{
if (ctx.args.size() < 2)
shared_commands::std_autocomplete(ctx);
else
if (ctx.args.size() == 0)
{
if (ctx.args.size() == 2)
{
std::set<std::string> templates = gTemplateManager().get_template_list();
for (const auto &template_name : templates)
rawout << template_name << std::endl;
}
// First arg: server name
shared_commands::std_autocomplete(ctx);
}
else if (ctx.args.size() == 1)
{
// Second arg: template name
std::set<std::string> templates = gTemplateManager().get_template_list();
for (const auto &template_name : templates)
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;
}
}