Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions build/Build.Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ $version = Get-SemVer
Write-Output "Building version $version"

$framework = 'net9.0'
$windowsTfmSuffix = '-windows'

function Clean-Output
{
Expand All @@ -28,7 +27,7 @@ function Restore-Packages

function Execute-Tests($version)
{
& dotnet test ./test/SeqCli.Tests/SeqCli.Tests.csproj -c Release --framework "$framework$windowsTfmSuffix" /p:Configuration=Release /p:Platform=x64 /p:VersionPrefix=$version
& dotnet test ./test/SeqCli.Tests/SeqCli.Tests.csproj -c Release --framework "$framework" /p:Configuration=Release /p:Platform=x64 /p:VersionPrefix=$version
if($LASTEXITCODE -ne 0) { throw "Build failed" }
}

Expand All @@ -39,12 +38,9 @@ function Create-ArtifactDir

function Publish-Archives($version)
{
$rids = $([xml](Get-Content .\src\SeqCli\SeqCli.csproj)).Project.PropertyGroup.RuntimeIdentifiers[0].Split(';')
$rids = $([xml](Get-Content .\src\SeqCli\SeqCli.csproj)).Project.PropertyGroup.RuntimeIdentifiers.Split(';')
foreach ($rid in $rids) {
$tfm = $framework
if ($rid -eq "win-x64") {
$tfm = "$tfm$windowsTfmSuffix"
}

& dotnet publish ./src/SeqCli/SeqCli.csproj -c Release -f $tfm -r $rid --self-contained /p:VersionPrefix=$version
if($LASTEXITCODE -ne 0) { throw "Build failed" }
Expand Down
4 changes: 3 additions & 1 deletion src/SeqCli/Cli/CommandAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ public class CommandAttribute : Attribute, ICommandMetadata
public string HelpText { get; }
public string? Example { get; set; }
public FeatureVisibility Visibility { get; set; }
public SupportedPlatforms Platforms { get; set; }

public CommandAttribute(string name, string helpText)
{
Name = name;
HelpText = helpText;
Visibility = FeatureVisibility.Visible;
Platforms = SupportedPlatforms.All;
}

public CommandAttribute(string name, string subCommand, string helpText) : this(name, helpText)
{
SubCommand = subCommand;
}
}
}
7 changes: 6 additions & 1 deletion src/SeqCli/Cli/CommandLineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Autofac.Features.Metadata;
using Serilog.Core;
Expand Down Expand Up @@ -55,8 +56,12 @@ public async Task<int> Run(string[] args, LoggingLevelSwitch levelSwitch)
if (args.Any(a => a.Trim() is prereleaseArg))
featureVisibility |= FeatureVisibility.Preview;

var currentPlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? SupportedPlatforms.Windows
: SupportedPlatforms.Posix;

var cmd = _availableCommands.SingleOrDefault(c =>
featureVisibility.HasFlag(c.Metadata.Visibility) &&
c.Metadata.Platforms.HasFlag(currentPlatform) && featureVisibility.HasFlag(c.Metadata.Visibility) &&
c.Metadata.Name == commandName &&
(c.Metadata.SubCommand == subCommandName || c.Metadata.SubCommand == null));

Expand Down
1 change: 1 addition & 0 deletions src/SeqCli/Cli/CommandMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public class CommandMetadata : ICommandMetadata
public required string HelpText { get; set; }
public string? Example { get; set; }
public FeatureVisibility Visibility { get; set; }
public SupportedPlatforms Platforms { get; set; }
}
9 changes: 3 additions & 6 deletions src/SeqCli/Cli/Commands/Forwarder/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if WINDOWS

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Threading.Tasks;
using SeqCli.Cli.Features;
Expand All @@ -29,7 +28,7 @@ namespace SeqCli.Cli.Commands.Forwarder;

// ReSharper disable once ClassNeverInstantiated.Global

[Command("forwarder", "install", "Install the forwarder as a Windows service", Visibility = FeatureVisibility.Preview)]
[Command("forwarder", "install", "Install the forwarder as a Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
class InstallCommand : Command
{
Expand Down Expand Up @@ -100,7 +99,7 @@ void Install()
if (netshResult != 0)
Console.WriteLine($"Could not add URL reservation for {listenUri}: `netsh` returned {netshResult}; ignoring");

var exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Program.BinaryName);
var exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Program.WindowsBinaryName);
var forwarderRunCmdline = $"\"{exePath}\" forwarder run --pre --storage=\"{_storagePath.StorageRootPath}\"";

var binPath = forwarderRunCmdline.Replace("\"", "\\\"");
Expand Down Expand Up @@ -149,5 +148,3 @@ static string MakeListenUriReservationPattern(string uri)
return listenUri;
}
}

#endif
6 changes: 1 addition & 5 deletions src/SeqCli/Cli/Commands/Forwarder/RestartCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if WINDOWS

using System;
using System.Diagnostics.CodeAnalysis;
using System.ServiceProcess;
Expand All @@ -24,7 +22,7 @@

namespace SeqCli.Cli.Commands.Forwarder;

[Command("forwarder", "restart", "Restart the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
[Command("forwarder", "restart", "Restart the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
class RestartCommand : Command
{
Expand Down Expand Up @@ -80,5 +78,3 @@ protected override Task<int> Run()
}
}
}

#endif
35 changes: 19 additions & 16 deletions src/SeqCli/Cli/Commands/Forwarder/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Autofac;
Expand All @@ -36,10 +37,8 @@
using Serilog.Events;
using Serilog.Formatting.Compact;

#if WINDOWS
using System.Security.Cryptography.X509Certificates;
using SeqCli.Forwarder.ServiceProcess;
#endif

// ReSharper disable UnusedType.Global

Expand Down Expand Up @@ -134,12 +133,16 @@ protected override async Task<int> Run(string[] unrecognized)
{
options.Listen(ipAddress, apiListenUri.Port, listenOptions =>
{
#if WINDOWS
listenOptions.UseHttps(StoreName.My, apiListenUri.Host,
location: StoreLocation.LocalMachine, allowInvalid: true);
#else
listenOptions.UseHttps();
#endif
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
listenOptions.UseHttps(StoreName.My, apiListenUri.Host,
location: StoreLocation.LocalMachine, allowInvalid: true);
}
else
{
listenOptions.UseHttps();
}

});
}
else
Expand Down Expand Up @@ -193,14 +196,14 @@ protected override async Task<int> Run(string[] unrecognized)
// ReSharper disable once UnusedParameter.Local
static int RunService(ServerService service)
{
#if WINDOWS
System.ServiceProcess.ServiceBase.Run([
new SeqCliForwarderWindowsService(service)
]);
return 0;
#else
throw new NotSupportedException("Windows services are not supported on this platform.");
#endif
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
throw new NotSupportedException("Windows services are not supported on this platform.");


System.ServiceProcess.ServiceBase.Run([
new SeqCliForwarderWindowsService(service)
]);
return 0;
}

static async Task<int> RunStandardIOAsync(ServerService service, TextWriter cout)
Expand Down
6 changes: 1 addition & 5 deletions src/SeqCli/Cli/Commands/Forwarder/StartCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if WINDOWS

using System;
using System.Diagnostics.CodeAnalysis;
using System.ServiceProcess;
Expand All @@ -22,7 +20,7 @@

namespace SeqCli.Cli.Commands.Forwarder;

[Command("forwarder", "start", "Start the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
[Command("forwarder", "start", "Start the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
class StartCommand : Command
{
Expand Down Expand Up @@ -64,5 +62,3 @@ protected override Task<int> Run()
}
}
}

#endif
6 changes: 1 addition & 5 deletions src/SeqCli/Cli/Commands/Forwarder/StatusCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if WINDOWS

using System;
using System.Diagnostics.CodeAnalysis;
using System.ServiceProcess;
Expand All @@ -22,7 +20,7 @@

namespace SeqCli.Cli.Commands.Forwarder;

[Command("forwarder", "status", "Show the status of the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
[Command("forwarder", "status", "Show the status of the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
class StatusCommand : Command
{
Expand All @@ -48,5 +46,3 @@ protected override Task<int> Run()
return Task.FromResult(1);
}
}

#endif
6 changes: 1 addition & 5 deletions src/SeqCli/Cli/Commands/Forwarder/StopCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if WINDOWS

using System;
using System.Diagnostics.CodeAnalysis;
using System.ServiceProcess;
Expand All @@ -22,7 +20,7 @@

namespace SeqCli.Cli.Commands.Forwarder;

[Command("forwarder", "stop", "Stop the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
[Command("forwarder", "stop", "Stop the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
class StopCommand : Command
{
Expand Down Expand Up @@ -65,5 +63,3 @@ protected override Task<int> Run()
}
}
}

#endif
6 changes: 1 addition & 5 deletions src/SeqCli/Cli/Commands/Forwarder/UninstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if WINDOWS

using System;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -22,7 +20,7 @@

namespace SeqCli.Cli.Commands.Forwarder;

[Command("forwarder", "uninstall", "Uninstall the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
[Command("forwarder", "uninstall", "Uninstall the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
class UninstallCommand : Command
{
protected override Task<int> Run()
Expand All @@ -46,5 +44,3 @@ protected override Task<int> Run()
}
}
}

#endif
30 changes: 26 additions & 4 deletions src/SeqCli/Cli/Commands/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Autofac.Features.Metadata;
using CommandList = System.Collections.Generic.List<Autofac.Features.Metadata.Meta<System.Lazy<SeqCli.Cli.Command>, SeqCli.Cli.CommandMetadata>>;
Expand All @@ -25,10 +26,14 @@ namespace SeqCli.Cli.Commands;
[Command("help", "Show information about available commands", Example = "seqcli help search")]
class HelpCommand : Command
{
readonly SupportedPlatforms _currentPlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? SupportedPlatforms.Windows
: SupportedPlatforms.Posix;

readonly IEnumerable<Meta<Lazy<Command>, CommandMetadata>> _allCommands;
bool _markdown;
FeatureVisibility _included = FeatureVisibility.Visible;

public HelpCommand(IEnumerable<Meta<Lazy<Command>, CommandMetadata>> allCommands)
{
_allCommands = allCommands.OrderBy(c => c.Metadata.Name).ToList();
Expand All @@ -38,12 +43,12 @@ public HelpCommand(IEnumerable<Meta<Lazy<Command>, CommandMetadata>> allCommands
Options.Add("m|markdown", "Generate markdown for use in documentation", _ => _markdown = true);
}

IEnumerable<Meta<Lazy<Command>, CommandMetadata>> AvailableCommands() =>
_allCommands.Where(c => _included.HasFlag(c.Metadata.Visibility));
IEnumerable<Meta<Lazy<Command>, CommandMetadata>> AvailableCommands(SupportedPlatforms platform, FeatureVisibility visibility) =>
_allCommands.Where(c => (c.Metadata.Platforms & platform) != SupportedPlatforms.None && visibility.HasFlag(c.Metadata.Visibility));

protected override Task<int> Run(string[] unrecognized)
{
var orderedCommands = AvailableCommands()
var orderedCommands = (_markdown ? AvailableCommands(SupportedPlatforms.All, FeatureVisibility.Visible | FeatureVisibility.Preview) : AvailableCommands(_currentPlatform, _included))
.OrderBy(c => c.Metadata.Name)
.ThenBy(c => c.Metadata.SubCommand)
.ToList();
Expand Down Expand Up @@ -142,6 +147,23 @@ static void PrintMarkdownHelp(string executableName, CommandList orderedCommands
else
Console.WriteLine($"### `{cmd.Metadata.Name}`");
Console.WriteLine();
if (cmd.Metadata.Platforms != SupportedPlatforms.All ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one level of nesting more than is required.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are pulled under the one quote > block 👍

cmd.Metadata.Visibility == FeatureVisibility.Preview)
{
Console.Write(">");
if (cmd.Metadata.Visibility == FeatureVisibility.Preview)
{
Console.Write(" Preview command: only available when the `--pre` command-line flag is specified.");
}

if (cmd.Metadata.Platforms != SupportedPlatforms.All)
{
Console.Write($" This command is supported on **{cmd.Metadata.Platforms}** platforms only.");
}
Console.WriteLine();
Console.WriteLine();
}

Console.WriteLine(cmd.Metadata.HelpText + ".");
Console.WriteLine();

Expand Down
4 changes: 0 additions & 4 deletions src/SeqCli/Cli/Features/ServiceCredentialsFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if WINDOWS

using SeqCli.Cli;

namespace SeqCli.Forwarder.Cli.Features
Expand All @@ -38,5 +36,3 @@ public override void Enable(OptionSet options)
}
}
}

#endif
Loading