From ebdfa0610edebbbef1f3f6f418b6d29d837d52fd Mon Sep 17 00:00:00 2001 From: Liam McLennan Date: Thu, 29 Feb 2024 09:33:03 +1000 Subject: [PATCH 1/3] Add forwarder commands --- src/SeqCli/Cli/Commands/Forward/DumpCommand.cs | 13 +++++++++++++ src/SeqCli/Cli/Commands/Forward/InstallCommand.cs | 13 +++++++++++++ src/SeqCli/Cli/Commands/Forward/RestartCommand.cs | 13 +++++++++++++ src/SeqCli/Cli/Commands/Forward/RunCommand.cs | 13 +++++++++++++ src/SeqCli/Cli/Commands/Forward/StartCommand.cs | 13 +++++++++++++ src/SeqCli/Cli/Commands/Forward/StatusCommand.cs | 13 +++++++++++++ src/SeqCli/Cli/Commands/Forward/StopCommand.cs | 13 +++++++++++++ src/SeqCli/Cli/Commands/Forward/TruncateCommand.cs | 13 +++++++++++++ .../Cli/Commands/Forward/UninstallCommand.cs | 14 ++++++++++++++ 9 files changed, 118 insertions(+) create mode 100644 src/SeqCli/Cli/Commands/Forward/DumpCommand.cs create mode 100644 src/SeqCli/Cli/Commands/Forward/InstallCommand.cs create mode 100644 src/SeqCli/Cli/Commands/Forward/RestartCommand.cs create mode 100644 src/SeqCli/Cli/Commands/Forward/RunCommand.cs create mode 100644 src/SeqCli/Cli/Commands/Forward/StartCommand.cs create mode 100644 src/SeqCli/Cli/Commands/Forward/StatusCommand.cs create mode 100644 src/SeqCli/Cli/Commands/Forward/StopCommand.cs create mode 100644 src/SeqCli/Cli/Commands/Forward/TruncateCommand.cs create mode 100644 src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs diff --git a/src/SeqCli/Cli/Commands/Forward/DumpCommand.cs b/src/SeqCli/Cli/Commands/Forward/DumpCommand.cs new file mode 100644 index 00000000..02b7c3cd --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/DumpCommand.cs @@ -0,0 +1,13 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +[Command("forward", "dump", "Print the complete log buffer contents as JSON", + Example = "seqcli forward dump")] +class DumpCommand : Command +{ + public DumpCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs b/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs new file mode 100644 index 00000000..b544be20 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs @@ -0,0 +1,13 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +[Command("forward", "install", "Install the Seq Forwarder as a Windows service", + Example = "seqcli forward install")] +class InstallCommand : Command +{ + public InstallCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs b/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs new file mode 100644 index 00000000..8bbda6f7 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs @@ -0,0 +1,13 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +[Command("forward", "restart", "Restart the Seq Forwarder Windows service", + Example = "seqcli forward restart")] +class RestartCommand : Command +{ + public RestartCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/RunCommand.cs b/src/SeqCli/Cli/Commands/Forward/RunCommand.cs new file mode 100644 index 00000000..e95b0936 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/RunCommand.cs @@ -0,0 +1,13 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +[Command("forward", "run", "Run the Seq Forwarder server interactively", + Example = "seqcli forward run")] +class RunCommand : Command +{ + public RunCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/StartCommand.cs b/src/SeqCli/Cli/Commands/Forward/StartCommand.cs new file mode 100644 index 00000000..41946624 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/StartCommand.cs @@ -0,0 +1,13 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +[Command("forward", "start", "Start the Seq Forwarder Windows service", + Example = "seqcli forward start")] +class StartCommand : Command +{ + public StartCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs b/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs new file mode 100644 index 00000000..e4b408dc --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs @@ -0,0 +1,13 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +[Command("forward", "status", "Show the status of the Seq Forwarder service", + Example = "seqcli forward status")] +class StatusCommand : Command +{ + public StatusCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/StopCommand.cs b/src/SeqCli/Cli/Commands/Forward/StopCommand.cs new file mode 100644 index 00000000..b9e6c514 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/StopCommand.cs @@ -0,0 +1,13 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +[Command("forward", "stop", "Stop the Seq Forwarder service", + Example = "seqcli forward stop")] +class StopCommand : Command +{ + public StopCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/TruncateCommand.cs b/src/SeqCli/Cli/Commands/Forward/TruncateCommand.cs new file mode 100644 index 00000000..5499424f --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/TruncateCommand.cs @@ -0,0 +1,13 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +[Command("forward", "truncate", "Clear the log buffer contents", + Example = "seqcli forward truncate")] +class TruncateCommand : Command +{ + public TruncateCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs b/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs new file mode 100644 index 00000000..8416d5d7 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs @@ -0,0 +1,14 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +[Command("forward", "uninstall", "Uninstall the Windows service", + Example = "seqcli forward uninstall")] +internal class UninstallCommand : Command +{ + public UninstallCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} + From 8d4bcca7149e372cf09fe22caf83fb55bda21166 Mon Sep 17 00:00:00 2001 From: Liam McLennan Date: Thu, 29 Feb 2024 09:45:43 +1000 Subject: [PATCH 2/3] Conditional compilation --- src/SeqCli/Cli/Commands/Forward/InstallCommand.cs | 6 +++++- src/SeqCli/Cli/Commands/Forward/RestartCommand.cs | 6 +++++- src/SeqCli/Cli/Commands/Forward/StartCommand.cs | 6 +++++- src/SeqCli/Cli/Commands/Forward/StatusCommand.cs | 6 +++++- src/SeqCli/Cli/Commands/Forward/StopCommand.cs | 6 +++++- .../Cli/Commands/Forward/UninstallCommand.cs | 3 +++ src/SeqCli/SeqCli.csproj | 14 ++++++++++++++ 7 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs b/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs index b544be20..2004c358 100644 --- a/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs @@ -3,6 +3,8 @@ namespace SeqCli.Cli.Commands.Forward; +#if Windows + [Command("forward", "install", "Install the Seq Forwarder as a Windows service", Example = "seqcli forward install")] class InstallCommand : Command @@ -10,4 +12,6 @@ class InstallCommand : Command public InstallCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) { } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs b/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs index 8bbda6f7..7533777d 100644 --- a/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs @@ -3,6 +3,8 @@ namespace SeqCli.Cli.Commands.Forward; +#if Windows + [Command("forward", "restart", "Restart the Seq Forwarder Windows service", Example = "seqcli forward restart")] class RestartCommand : Command @@ -10,4 +12,6 @@ class RestartCommand : Command public RestartCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) { } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/StartCommand.cs b/src/SeqCli/Cli/Commands/Forward/StartCommand.cs index 41946624..3827c210 100644 --- a/src/SeqCli/Cli/Commands/Forward/StartCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/StartCommand.cs @@ -3,6 +3,8 @@ namespace SeqCli.Cli.Commands.Forward; +#if Windows + [Command("forward", "start", "Start the Seq Forwarder Windows service", Example = "seqcli forward start")] class StartCommand : Command @@ -10,4 +12,6 @@ class StartCommand : Command public StartCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) { } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs b/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs index e4b408dc..ce83e847 100644 --- a/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs @@ -3,6 +3,8 @@ namespace SeqCli.Cli.Commands.Forward; +#if Windows + [Command("forward", "status", "Show the status of the Seq Forwarder service", Example = "seqcli forward status")] class StatusCommand : Command @@ -10,4 +12,6 @@ class StatusCommand : Command public StatusCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) { } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/StopCommand.cs b/src/SeqCli/Cli/Commands/Forward/StopCommand.cs index b9e6c514..8ecc2ae0 100644 --- a/src/SeqCli/Cli/Commands/Forward/StopCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/StopCommand.cs @@ -3,6 +3,8 @@ namespace SeqCli.Cli.Commands.Forward; +#if Windows + [Command("forward", "stop", "Stop the Seq Forwarder service", Example = "seqcli forward stop")] class StopCommand : Command @@ -10,4 +12,6 @@ class StopCommand : Command public StopCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) { } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs b/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs index 8416d5d7..d5a16ba3 100644 --- a/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs @@ -3,6 +3,8 @@ namespace SeqCli.Cli.Commands.Forward; +#if Windows + [Command("forward", "uninstall", "Uninstall the Windows service", Example = "seqcli forward uninstall")] internal class UninstallCommand : Command @@ -12,3 +14,4 @@ public UninstallCommand(SeqConnectionFactory connectionFactory, SeqCliConfig con } } +#endif \ No newline at end of file diff --git a/src/SeqCli/SeqCli.csproj b/src/SeqCli/SeqCli.csproj index 0ee292ec..aa128458 100644 --- a/src/SeqCli/SeqCli.csproj +++ b/src/SeqCli/SeqCli.csproj @@ -12,7 +12,21 @@ seqcli default enable + true + true + true + + + Windows + + + OSX + + + Linux + + From d1ab1cd09b5a825603d324fe83b69e7ca8b6da77 Mon Sep 17 00:00:00 2001 From: Liam McLennan Date: Thu, 29 Feb 2024 10:20:37 +1000 Subject: [PATCH 3/3] Change casing of compilation symbols --- .../Cli/Commands/Forward/InstallCommand.cs | 2 +- .../Cli/Commands/Forward/RestartCommand.cs | 2 +- src/SeqCli/Cli/Commands/Forward/RunCommand.cs | 10 ++++ .../Cli/Commands/Forward/StartCommand.cs | 2 +- .../Cli/Commands/Forward/StatusCommand.cs | 2 +- .../Cli/Commands/Forward/StopCommand.cs | 2 +- .../Cli/Commands/Forward/UninstallCommand.cs | 2 +- src/SeqCli/Cli/Features/ListenUriFeature.cs | 13 +++++ src/SeqCli/Cli/Features/StoragePathFeature.cs | 58 +++++++++++++++++++ src/SeqCli/SeqCli.csproj | 4 +- 10 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 src/SeqCli/Cli/Features/ListenUriFeature.cs create mode 100644 src/SeqCli/Cli/Features/StoragePathFeature.cs diff --git a/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs b/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs index 2004c358..4288dfab 100644 --- a/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs @@ -3,7 +3,7 @@ namespace SeqCli.Cli.Commands.Forward; -#if Windows +#if WINDOWS [Command("forward", "install", "Install the Seq Forwarder as a Windows service", Example = "seqcli forward install")] diff --git a/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs b/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs index 7533777d..0d6cc8e7 100644 --- a/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs @@ -3,7 +3,7 @@ namespace SeqCli.Cli.Commands.Forward; -#if Windows +#if WINDOWS [Command("forward", "restart", "Restart the Seq Forwarder Windows service", Example = "seqcli forward restart")] diff --git a/src/SeqCli/Cli/Commands/Forward/RunCommand.cs b/src/SeqCli/Cli/Commands/Forward/RunCommand.cs index e95b0936..f2b0ed66 100644 --- a/src/SeqCli/Cli/Commands/Forward/RunCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/RunCommand.cs @@ -1,3 +1,4 @@ +using SeqCli.Cli.Features; using SeqCli.Config; using SeqCli.Connection; @@ -7,7 +8,16 @@ namespace SeqCli.Cli.Commands.Forward; Example = "seqcli forward run")] class RunCommand : Command { +#pragma warning disable CS0414 // Field is assigned but its value is never used + bool _noLogo; +#pragma warning restore CS0414 // Field is assigned but its value is never used + readonly StoragePathFeature _storagePath; + readonly ListenUriFeature _listenUri; + public RunCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) { + Options.Add("nologo", _ => _noLogo = true); + _storagePath = Enable(); + _listenUri = Enable(); } } \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Forward/StartCommand.cs b/src/SeqCli/Cli/Commands/Forward/StartCommand.cs index 3827c210..6ddb52dc 100644 --- a/src/SeqCli/Cli/Commands/Forward/StartCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/StartCommand.cs @@ -3,7 +3,7 @@ namespace SeqCli.Cli.Commands.Forward; -#if Windows +#if WINDOWS [Command("forward", "start", "Start the Seq Forwarder Windows service", Example = "seqcli forward start")] diff --git a/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs b/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs index ce83e847..d9f1f736 100644 --- a/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs @@ -3,7 +3,7 @@ namespace SeqCli.Cli.Commands.Forward; -#if Windows +#if WINDOWS [Command("forward", "status", "Show the status of the Seq Forwarder service", Example = "seqcli forward status")] diff --git a/src/SeqCli/Cli/Commands/Forward/StopCommand.cs b/src/SeqCli/Cli/Commands/Forward/StopCommand.cs index 8ecc2ae0..06bc93b4 100644 --- a/src/SeqCli/Cli/Commands/Forward/StopCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/StopCommand.cs @@ -3,7 +3,7 @@ namespace SeqCli.Cli.Commands.Forward; -#if Windows +#if WINDOWS [Command("forward", "stop", "Stop the Seq Forwarder service", Example = "seqcli forward stop")] diff --git a/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs b/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs index d5a16ba3..a8fa690f 100644 --- a/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs @@ -3,7 +3,7 @@ namespace SeqCli.Cli.Commands.Forward; -#if Windows +#if WINDOWS [Command("forward", "uninstall", "Uninstall the Windows service", Example = "seqcli forward uninstall")] diff --git a/src/SeqCli/Cli/Features/ListenUriFeature.cs b/src/SeqCli/Cli/Features/ListenUriFeature.cs new file mode 100644 index 00000000..15c5352e --- /dev/null +++ b/src/SeqCli/Cli/Features/ListenUriFeature.cs @@ -0,0 +1,13 @@ +namespace SeqCli.Cli.Features; + +class ListenUriFeature : CommandFeature +{ + public string? ListenUri { get; private set; } + + public override void Enable(OptionSet options) + { + options.Add("l=|listen=", + "Set the listen Uri; http://localhost:15341/ is used by default.", + v => ListenUri = v); + } +} \ No newline at end of file diff --git a/src/SeqCli/Cli/Features/StoragePathFeature.cs b/src/SeqCli/Cli/Features/StoragePathFeature.cs new file mode 100644 index 00000000..ce363a44 --- /dev/null +++ b/src/SeqCli/Cli/Features/StoragePathFeature.cs @@ -0,0 +1,58 @@ +using System; +using System.IO; + +namespace SeqCli.Cli.Features; + +class StoragePathFeature : CommandFeature +{ + string? _storageRoot; + + public string StorageRootPath + { + get + { + if (!string.IsNullOrWhiteSpace(_storageRoot)) + return _storageRoot; + + return TryQueryInstalledStorageRoot() ?? GetDefaultStorageRoot(); + } + } + + public string ConfigFilePath => Path.Combine(StorageRootPath, "SeqForwarder.json"); + + public string BufferPath => Path.Combine(StorageRootPath, "Buffer"); + + public override void Enable(OptionSet options) + { + options.Add("s=|storage=", + "Set the folder where data will be stored; " + + "" + GetDefaultStorageRoot() + " is used by default.", + v => _storageRoot = Path.GetFullPath(v)); + } + + static string GetDefaultStorageRoot() + { + return Path.GetFullPath(Path.Combine( +#if WINDOWS + // Common, here, because the service may run as Local Service, which has no obvious home + // directory. + Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), +#else + // Specific to and writable by the current user. + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), +#endif + "Seq", + "Forwarder")); + } + + static string? TryQueryInstalledStorageRoot() + { +#if WINDOWS + // if (Seq.Forwarder.Util.ServiceConfiguration.GetServiceStoragePath( + // Seq.Forwarder.ServiceProcess.SeqForwarderWindowsService.WindowsServiceName, out var storage)) + // return storage; +#endif + + return null; + } +} \ No newline at end of file diff --git a/src/SeqCli/SeqCli.csproj b/src/SeqCli/SeqCli.csproj index aa128458..54e9377f 100644 --- a/src/SeqCli/SeqCli.csproj +++ b/src/SeqCli/SeqCli.csproj @@ -18,13 +18,13 @@ - Windows + WINDOWS OSX - Linux + LINUX