Skip to content

Commit 272f232

Browse files
committed
Include platform support and preview status in generated Markdown help
1 parent 486f7ea commit 272f232

11 files changed

+55
-12
lines changed

src/SeqCli/Cli/CommandAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ public class CommandAttribute : Attribute, ICommandMetadata
2424
public string HelpText { get; }
2525
public string? Example { get; set; }
2626
public FeatureVisibility Visibility { get; set; }
27+
public SupportedPlatforms Platforms { get; set; }
2728

2829
public CommandAttribute(string name, string helpText)
2930
{
3031
Name = name;
3132
HelpText = helpText;
3233
Visibility = FeatureVisibility.Visible;
34+
Platforms = SupportedPlatforms.All;
3335
}
3436

3537
public CommandAttribute(string name, string subCommand, string helpText) : this(name, helpText)
3638
{
3739
SubCommand = subCommand;
3840
}
39-
}
41+
}

src/SeqCli/Cli/CommandLineHost.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Collections.Generic;
1717
using System.Linq;
1818
using System.Reflection;
19+
using System.Runtime.InteropServices;
1920
using System.Threading.Tasks;
2021
using Autofac.Features.Metadata;
2122
using Serilog.Core;
@@ -55,8 +56,12 @@ public async Task<int> Run(string[] args, LoggingLevelSwitch levelSwitch)
5556
if (args.Any(a => a.Trim() is prereleaseArg))
5657
featureVisibility |= FeatureVisibility.Preview;
5758

59+
var currentPlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
60+
? SupportedPlatforms.Windows
61+
: SupportedPlatforms.Unix;
62+
5863
var cmd = _availableCommands.SingleOrDefault(c =>
59-
featureVisibility.HasFlag(c.Metadata.Visibility) &&
64+
c.Metadata.Platforms.HasFlag(currentPlatform) && featureVisibility.HasFlag(c.Metadata.Visibility) &&
6065
c.Metadata.Name == commandName &&
6166
(c.Metadata.SubCommand == subCommandName || c.Metadata.SubCommand == null));
6267

src/SeqCli/Cli/CommandMetadata.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ public class CommandMetadata : ICommandMetadata
2121
public required string HelpText { get; set; }
2222
public string? Example { get; set; }
2323
public FeatureVisibility Visibility { get; set; }
24+
public SupportedPlatforms Platforms { get; set; }
2425
}

src/SeqCli/Cli/Commands/Forwarder/InstallCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System;
1616
using System.Diagnostics.CodeAnalysis;
1717
using System.IO;
18+
using System.Runtime.InteropServices;
1819
using System.Security.AccessControl;
1920
using System.Threading.Tasks;
2021
using SeqCli.Cli.Features;
@@ -27,7 +28,7 @@ namespace SeqCli.Cli.Commands.Forwarder;
2728

2829
// ReSharper disable once ClassNeverInstantiated.Global
2930

30-
[Command("forwarder", "install", "Install the forwarder as a Windows service", Visibility = FeatureVisibility.Preview)]
31+
[Command("forwarder", "install", "Install the forwarder as a Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
3132
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
3233
class InstallCommand : Command
3334
{

src/SeqCli/Cli/Commands/Forwarder/RestartCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace SeqCli.Cli.Commands.Forwarder;
2424

25-
[Command("forwarder", "restart", "Restart the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
25+
[Command("forwarder", "restart", "Restart the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
2626
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
2727
class RestartCommand : Command
2828
{

src/SeqCli/Cli/Commands/Forwarder/StartCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace SeqCli.Cli.Commands.Forwarder;
2222

23-
[Command("forwarder", "start", "Start the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
23+
[Command("forwarder", "start", "Start the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
2424
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
2525
class StartCommand : Command
2626
{

src/SeqCli/Cli/Commands/Forwarder/StatusCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace SeqCli.Cli.Commands.Forwarder;
2222

23-
[Command("forwarder", "status", "Show the status of the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
23+
[Command("forwarder", "status", "Show the status of the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
2424
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
2525
class StatusCommand : Command
2626
{

src/SeqCli/Cli/Commands/Forwarder/StopCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace SeqCli.Cli.Commands.Forwarder;
2222

23-
[Command("forwarder", "stop", "Stop the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
23+
[Command("forwarder", "stop", "Stop the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
2424
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
2525
class StopCommand : Command
2626
{

src/SeqCli/Cli/Commands/Forwarder/UninstallCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace SeqCli.Cli.Commands.Forwarder;
2222

23-
[Command("forwarder", "uninstall", "Uninstall the forwarder Windows service", Visibility = FeatureVisibility.Preview)]
23+
[Command("forwarder", "uninstall", "Uninstall the forwarder Windows service", Visibility = FeatureVisibility.Preview, Platforms = SupportedPlatforms.Windows)]
2424
class UninstallCommand : Command
2525
{
2626
protected override Task<int> Run()

src/SeqCli/Cli/Commands/HelpCommand.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Collections.Generic;
1717
using System.Linq;
1818
using System.Reflection;
19+
using System.Runtime.InteropServices;
1920
using System.Threading.Tasks;
2021
using Autofac.Features.Metadata;
2122
using CommandList = System.Collections.Generic.List<Autofac.Features.Metadata.Meta<System.Lazy<SeqCli.Cli.Command>, SeqCli.Cli.CommandMetadata>>;
@@ -25,10 +26,14 @@ namespace SeqCli.Cli.Commands;
2526
[Command("help", "Show information about available commands", Example = "seqcli help search")]
2627
class HelpCommand : Command
2728
{
29+
readonly SupportedPlatforms _currentPlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
30+
? SupportedPlatforms.Windows
31+
: SupportedPlatforms.Unix;
32+
2833
readonly IEnumerable<Meta<Lazy<Command>, CommandMetadata>> _allCommands;
2934
bool _markdown;
3035
FeatureVisibility _included = FeatureVisibility.Visible;
31-
36+
3237
public HelpCommand(IEnumerable<Meta<Lazy<Command>, CommandMetadata>> allCommands)
3338
{
3439
_allCommands = allCommands.OrderBy(c => c.Metadata.Name).ToList();
@@ -38,12 +43,12 @@ public HelpCommand(IEnumerable<Meta<Lazy<Command>, CommandMetadata>> allCommands
3843
Options.Add("m|markdown", "Generate markdown for use in documentation", _ => _markdown = true);
3944
}
4045

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

4449
protected override Task<int> Run(string[] unrecognized)
4550
{
46-
var orderedCommands = AvailableCommands()
51+
var orderedCommands = (_markdown ? AvailableCommands(SupportedPlatforms.All, FeatureVisibility.Visible | FeatureVisibility.Preview) : AvailableCommands(_currentPlatform, _included))
4752
.OrderBy(c => c.Metadata.Name)
4853
.ThenBy(c => c.Metadata.SubCommand)
4954
.ToList();
@@ -142,6 +147,23 @@ static void PrintMarkdownHelp(string executableName, CommandList orderedCommands
142147
else
143148
Console.WriteLine($"### `{cmd.Metadata.Name}`");
144149
Console.WriteLine();
150+
if (cmd.Metadata.Platforms != SupportedPlatforms.All ||
151+
cmd.Metadata.Visibility == FeatureVisibility.Preview)
152+
{
153+
Console.Write(">");
154+
if (cmd.Metadata.Visibility == FeatureVisibility.Preview)
155+
{
156+
Console.Write(" Preview command: only available when the `--pre` command-line flag is specified.");
157+
}
158+
159+
if (cmd.Metadata.Platforms != SupportedPlatforms.All)
160+
{
161+
Console.Write($" This command is supported on **{cmd.Metadata.Platforms}** platforms only.");
162+
}
163+
Console.WriteLine();
164+
Console.WriteLine();
165+
}
166+
145167
Console.WriteLine(cmd.Metadata.HelpText + ".");
146168
Console.WriteLine();
147169

0 commit comments

Comments
 (0)