aboutsummaryrefslogtreecommitdiff
path: root/src/zen/cmds/service_cmd.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-01-10 15:52:34 +0100
committerDan Engelbrecht <[email protected]>2025-01-10 15:52:34 +0100
commit7a73a49de6ddbc6712554c5c9b2863dd8e7de0f2 (patch)
treeb317ca99590a087724717e191ee3e2bc05801f75 /src/zen/cmds/service_cmd.cpp
parentcleanups (diff)
downloadarchived-zen-7a73a49de6ddbc6712554c5c9b2863dd8e7de0f2.tar.xz
archived-zen-7a73a49de6ddbc6712554c5c9b2863dd8e7de0f2.zip
displayname and description are windows-only properties
Diffstat (limited to 'src/zen/cmds/service_cmd.cpp')
-rw-r--r--src/zen/cmds/service_cmd.cpp62
1 files changed, 34 insertions, 28 deletions
diff --git a/src/zen/cmds/service_cmd.cpp b/src/zen/cmds/service_cmd.cpp
index de3466eff..db60d9b54 100644
--- a/src/zen/cmds/service_cmd.cpp
+++ b/src/zen/cmds/service_cmd.cpp
@@ -160,6 +160,7 @@ ServiceCommand::ServiceCommand()
fmt::format("Service name, defaults to \"{}\"", m_ServiceName),
cxxopts::value(m_ServiceName),
"<name>");
+#if ZEN_PLATFORM_WINDOWS
m_InstallOptions.add_option("",
"d",
"display-name",
@@ -172,9 +173,6 @@ ServiceCommand::ServiceCommand()
fmt::format("Service description", m_ServiceDescription),
cxxopts::value(m_ServiceDescription),
"<description>");
- m_InstallOptions.parse_positional({"executable", "name", "display-name"});
- m_InstallOptions.positional_help("executable name display-name");
-#if ZEN_PLATFORM_WINDOWS
m_InstallOptions.add_option("",
"",
"allow-elevation",
@@ -182,6 +180,8 @@ ServiceCommand::ServiceCommand()
cxxopts::value(m_AllowElevation),
"<allow-elevation>");
#endif // ZEN_PLATFORM_WINDOWS
+ m_InstallOptions.parse_positional({"executable", "name", "display-name"});
+ m_InstallOptions.positional_help("executable name display-name");
m_UninstallOptions.add_options()("h,help", "Print help");
m_UninstallOptions.add_option("",
@@ -240,6 +240,27 @@ ServiceCommand::ServiceCommand()
ServiceCommand::~ServiceCommand() = default;
+std::string FmtServiceInfo(const ServiceInfo& Info, std::string_view Prefix)
+{
+ std::string Result = fmt::format(
+ "{}Status: {}\n"
+ "{}Executable: {}\n"
+ "{}CommandLineOptions: {}",
+ Prefix, ToString(Info.Status),
+ Prefix, Info.Spec.ExecutablePath,
+ Prefix, Info.Spec.CommandLineOptions);
+
+#if ZEN_PLATFORM_WINDOWS
+ Result += fmt::format("\n"
+ "{}Display Name: {}\n"
+ "{}Description: {}",
+ Prefix, Info.Spec.DisplayName,
+ Prefix, Info.Spec.Description);
+#endif // ZEN_PLATFORM_WINDOWS
+
+ return Result;
+}
+
int
ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
@@ -282,18 +303,9 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
else
{
ZEN_CONSOLE(
- "Service '{}':\n"
- " Status: {}\n"
- " Executable: {}\n"
- " CommandLineOptions: {}\n"
- " Display Name: {}\n"
- " Description: {}",
+ "Service '{}':\n{}",
m_ServiceName,
- ToString(Info.Status),
- Info.Spec.ExecutablePath,
- Info.Spec.CommandLineOptions,
- Info.Spec.DisplayName,
- Info.Spec.Description);
+ FmtServiceInfo(Info, " "));
}
}
@@ -304,18 +316,9 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (!Ec && Info.Status != ServiceStatus::NotInstalled)
{
ZEN_CONSOLE(
- "Service '{}' already installed:\n"
- " Status: {}\n"
- " Executable: {}\n"
- " CommandLineOptions: {}\n"
- " Display Name: {}\n"
- " Description: {}",
+ "Service '{}' already installed:\n{}",
m_ServiceName,
- ToString(Info.Status),
- Info.Spec.ExecutablePath,
- Info.Spec.CommandLineOptions,
- Info.Spec.DisplayName,
- Info.Spec.Description);
+ FmtServiceInfo(Info, " "));
return 1;
}
@@ -333,9 +336,12 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
m_ServerExecutable = std::filesystem::absolute(m_ServerExecutable);
Ec = InstallService(m_ServiceName,
ServiceSpec{.ExecutablePath = m_ServerExecutable,
- .CommandLineOptions = GlobalOptions.PassthroughCommandLine,
- .DisplayName = m_ServiceDisplayName,
- .Description = m_ServiceDescription});
+ .CommandLineOptions = GlobalOptions.PassthroughCommandLine
+ #if ZEN_PLATFORM_WINDOWS
+ ,.DisplayName = m_ServiceDisplayName
+ ,.Description = m_ServiceDescription
+ #endif // ZEN_PLATFORM_WINDOWS
+ });
if (Ec)
{
ZEN_CONSOLE("Failed to install service '{}' using '{}' . Reason: '{}'", m_ServiceName, m_ServerExecutable, Ec.message());