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..4288dfab --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/InstallCommand.cs @@ -0,0 +1,17 @@ +using SeqCli.Config; +using SeqCli.Connection; + +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 +{ + public InstallCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} + +#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 new file mode 100644 index 00000000..0d6cc8e7 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/RestartCommand.cs @@ -0,0 +1,17 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +#if WINDOWS + +[Command("forward", "restart", "Restart the Seq Forwarder Windows service", + Example = "seqcli forward restart")] +class RestartCommand : Command +{ + public RestartCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} + +#endif \ 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..f2b0ed66 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/RunCommand.cs @@ -0,0 +1,23 @@ +using SeqCli.Cli.Features; +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 +{ +#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 new file mode 100644 index 00000000..6ddb52dc --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/StartCommand.cs @@ -0,0 +1,17 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +#if WINDOWS + +[Command("forward", "start", "Start the Seq Forwarder Windows service", + Example = "seqcli forward start")] +class StartCommand : Command +{ + public StartCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} + +#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 new file mode 100644 index 00000000..d9f1f736 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/StatusCommand.cs @@ -0,0 +1,17 @@ +using SeqCli.Config; +using SeqCli.Connection; + +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 +{ + public StatusCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} + +#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 new file mode 100644 index 00000000..06bc93b4 --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/StopCommand.cs @@ -0,0 +1,17 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +#if WINDOWS + +[Command("forward", "stop", "Stop the Seq Forwarder service", + Example = "seqcli forward stop")] +class StopCommand : Command +{ + public StopCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} + +#endif \ 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..a8fa690f --- /dev/null +++ b/src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs @@ -0,0 +1,17 @@ +using SeqCli.Config; +using SeqCli.Connection; + +namespace SeqCli.Cli.Commands.Forward; + +#if WINDOWS + +[Command("forward", "uninstall", "Uninstall the Windows service", + Example = "seqcli forward uninstall")] +internal class UninstallCommand : Command +{ + public UninstallCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) + { + } +} + +#endif \ No newline at end of file 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 0ee292ec..54e9377f 100644 --- a/src/SeqCli/SeqCli.csproj +++ b/src/SeqCli/SeqCli.csproj @@ -12,7 +12,21 @@ seqcli default enable + true + true + true + + + WINDOWS + + + OSX + + + LINUX + +