Compare commits

..

9 Commits

Author SHA1 Message Date
Patrik Svensson
d90e94dbb3 Fix spacing in blog post 2025-10-10 21:27:37 +02:00
Patrik Svensson
169abca986 Add blog post for 0.52.0 2025-10-10 21:12:54 +02:00
Patrik Svensson
3c2156268c Remove global.json for docs project 2025-10-10 20:36:13 +02:00
Patrik Svensson
6fb81103f0 Update more dependencies 2025-10-10 20:32:48 +02:00
Patrik Svensson
880e83b27c Update Cake to 5.1.0 2025-10-10 20:20:50 +02:00
Patrik Svensson
0b270e1ccd Update dependencies 2025-10-10 20:13:21 +02:00
Mattias Karlsson
2d9e8069fd Fix OPENCLI_VISIBILITY_INTERNAL to DefineConstants concat 2025-10-06 23:19:10 +02:00
Patrik Svensson
b551bbd244 Add OpenCLI integration to Spectre.Console.Cli 2025-10-02 02:05:46 +02:00
Patrik Svensson
3a70fbec75 Update the blog post with info about 0.51.1 2025-09-07 01:04:05 +02:00
31 changed files with 595 additions and 82 deletions

View File

@@ -18,12 +18,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x

View File

@@ -24,12 +24,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
@@ -53,17 +53,17 @@ jobs:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v5
with:
node-version: '16'
node-version: '22'
- name: Cache dependencies
uses: actions/cache@v4

View File

@@ -38,8 +38,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Playwright" Version="1.52.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Playwright" Version="1.55.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Statiq.CodeAnalysis" Version="1.0.0-beta.72" />
<PackageReference Include="Statiq.Common" Version="1.0.0-beta.72" />
<PackageReference Include="Statiq.Web" Version="1.0.0-beta.60" />

View File

@@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Docs", "Docs.csproj", "{C337F609-A890-4E52-BDA3-91658039B0E3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C337F609-A890-4E52-BDA3-91658039B0E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C337F609-A890-4E52-BDA3-91658039B0E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C337F609-A890-4E52-BDA3-91658039B0E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C337F609-A890-4E52-BDA3-91658039B0E3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2FB3922B-494A-45EB-A479-FC507B8E107C}
EndGlobalSection
EndGlobal

3
docs/Docs.slnx Normal file
View File

@@ -0,0 +1,3 @@
<Solution>
<Project Path="Docs.csproj" />
</Solution>

View File

@@ -1,6 +0,0 @@
{
"sdk": {
"version": "9.0.202",
"rollForward": "latestFeature"
}
}

View File

@@ -1,11 +1,13 @@
Title: Spectre.Console 0.51 released!
Title: Spectre.Console 0.51.1 released!
Description: Not a substitute for human interaction.
Published: 2025-09-07
Category: Release Notes
Excluded: false
---
Version 0.51 of Spectre.Console has been released!
Version `0.51.1` of Spectre.Console has been released!
_Note: Due to an issue discovered after the release of version 0.51.0, that version has now been unlisted. Lets all pretend it never existed 😅_
## What's Changed
@@ -38,4 +40,4 @@ Version 0.51 of Spectre.Console has been released!
* [@mitchdenny](https://github.com/mitchdenny) made their first contribution in [#1881](https://github.com/spectreconsole/spectre.console/pull/1881)
* [@mattfennerom](https://github.com/mattfennerom) made their first contribution in [#1890](https://github.com/spectreconsole/spectre.console/pull/1890)
**Full Changelog**: [0.50.0...0.51.0](https://github.com/spectreconsole/spectre.console/compare/0.50.0...0.51.0)
**Full Changelog**: [0.50.0...0.51.0](https://github.com/spectreconsole/spectre.console/compare/0.50.0...0.51.1)

View File

@@ -0,0 +1,17 @@
Title: Spectre.Console 0.52.0 released!
Description: Don't eat (too much) glue.
Published: 2025-10-10
Category: Release Notes
Excluded: false
---
Version `0.52.0` of Spectre.Console has been released!
Exciting things are happening. Weve merged support for my love child, OpenCli, in this release. That means you can now pass the parameter `--help-dump-opencli` to your application to get an [OpenCli](https://opencli.org) description dumped to stdout.
## What's Changed
* Add OpenCLI integration to Spectre.Console.Cli by [@patriksvensson](https://github.com/patriksvensson) in [#1909](https://github.com/spectreconsole/spectre.console/pull/1909)
* Fix OPENCLI_VISIBILITY_INTERNAL to DefineConstants concat by [@devlead](https://github.com/devlead) in [#1912](https://github.com/spectreconsole/spectre.console/pull/1912)
**Full Changelog**: https://github.com/spectreconsole/spectre.console/compare/0.51.1...0.52.0

22
docs/input/cli/opencli.md Normal file
View File

@@ -0,0 +1,22 @@
Title: OpenCLI Integration
Order: 15
Description: OpenCLI integration
Highlights:
- Generate OpenCLI descriptions
---
From version `0.52.0` and above, you will be able to generate [OpenCLI](https://opencli.org)
descriptions from your `Spectre.Console.Cli` applications.
Simply add the `--help-dump-opencli` option to your application, and an
OpenCLI description will be written to stdout.
```shell
$ ./myapp --help-dump-opencli
```
If you want to save it to disk, pipe it to a file.
```shell
$ ./myapp --help-dump-opencli > myapp.openapi.json
```

View File

@@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "5.0.0",
"version": "5.1.0",
"commands": [
"dotnet-cake"
]

View File

@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/global",
"sdk": {
"version": "9.0.202",
"version": "9.0.305",
"rollForward": "latestFeature"
}
}

View File

@@ -45,9 +45,9 @@
<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.3.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Scriban" Version="6.2.1" />
<PackageReference Include="Spectre.IO" Version="0.18.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Scriban" Version="6.4.0" />
<PackageReference Include="Spectre.IO" Version="0.20.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -4,22 +4,23 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="IsExternalInit" Version="1.0.3" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="8.0.0" />
<PackageVersion Include="MinVer" PrivateAssets="All" Version="6.0.0" />
<PackageVersion Include="OpenCli.Sources" Version="0.5.0" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
<PackageVersion Include="Roslynator.Analyzers" PrivateAssets="All" Version="4.14.0" />
<PackageVersion Include="Roslynator.Analyzers" PrivateAssets="All" Version="4.14.1" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.11" />
<PackageVersion Include="Spectre.Verify.Extensions" Version="28.16.0" />
<PackageVersion Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.2.0-beta.556" />
<PackageVersion Include="System.Memory" Version="4.6.3" />
<PackageVersion Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" />
<PackageVersion Include="Verify.Xunit" Version="30.5.0" />
<PackageVersion Include="Wcwidth.Sources" Version="2.0.0" />
<PackageVersion Include="Verify.Xunit" Version="31.0.0" />
<PackageVersion Include="Wcwidth.Sources" Version="3.0.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.3">
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>

View File

@@ -79,6 +79,7 @@ public sealed class CommandApp : ICommandApp
cli.AddCommand<VersionCommand>(CliConstants.Commands.Version);
cli.AddCommand<XmlDocCommand>(CliConstants.Commands.XmlDoc);
cli.AddCommand<ExplainCommand>(CliConstants.Commands.Explain);
cli.AddCommand<OpenCliGeneratorCommand>(CliConstants.Commands.OpenCli);
});
_executed = true;

View File

@@ -68,6 +68,13 @@ internal sealed class CommandExecutor
}
}
}
// OpenCLI?
if (firstArgument.Equals(CliConstants.DumpHelpOpenCliOption, StringComparison.OrdinalIgnoreCase))
{
// Replace all arguments with the opencligen command
arguments = ["cli", "opencli"];
}
}
// Parse and map the model against the arguments.

View File

@@ -2,7 +2,7 @@ namespace Spectre.Console.Cli;
[Description("Displays diagnostics about CLI configurations")]
[SuppressMessage("Performance", "CA1812: Avoid uninstantiated internal classes")]
internal sealed class ExplainCommand : Command<ExplainCommand.Settings>
internal sealed class ExplainCommand : Command<ExplainCommand.Settings>, IBuiltInCommand
{
private readonly CommandModel _commandModel;
private readonly IAnsiConsole _writer;

View File

@@ -0,0 +1,9 @@
namespace Spectre.Console.Cli;
/// <summary>
/// Represents a built-in command.
/// Used as a marker interface.
/// </summary>
internal interface IBuiltInCommand : ICommand
{
}

View File

@@ -0,0 +1,224 @@
using OpenCli;
namespace Spectre.Console.Cli;
internal sealed class OpenCliGeneratorCommand : Command, IBuiltInCommand
{
private readonly IConfiguration _configuration;
private readonly CommandModel _model;
public OpenCliGeneratorCommand(IConfiguration configuration, CommandModel model)
{
_configuration = configuration;
_model = model ?? throw new ArgumentNullException(nameof(model));
}
public override int Execute(CommandContext context)
{
var document = new OpenCliDocument
{
OpenCli = "0.1-draft",
Info = new OpenCliInfo
{
Title = ((ICommandModel)_model).ApplicationName, Version = _model.ApplicationVersion ?? "1.0",
},
Commands = CreateCommands(_model.Commands),
Arguments = CreateArguments(_model.DefaultCommand?.GetArguments()),
Options = CreateOptions(_model.DefaultCommand?.GetOptions()),
};
var writer = _configuration.Settings.Console.GetConsole();
writer.WriteLine(document.Write());
return 0;
}
private List<OpenCliCommand> CreateCommands(IList<CommandInfo> commands)
{
var result = new List<OpenCliCommand>();
foreach (var command in commands.OrderBy(o => o.Name, StringComparer.OrdinalIgnoreCase))
{
if (typeof(IBuiltInCommand).IsAssignableFrom(command.CommandType))
{
continue;
}
var openCliCommand = new OpenCliCommand
{
Name = command.Name,
Aliases =
[
..command.Aliases.OrderBy(str => str)
],
Commands = CreateCommands(command.Children),
Arguments = CreateArguments(command.GetArguments()),
Options = CreateOptions(command.GetOptions()),
Description = command.Description,
Hidden = command.IsHidden,
Examples = [..command.Examples.Select(example => string.Join(" ", example))],
};
// Skip branches without commands
if (command.IsBranch && openCliCommand.Commands.Count == 0)
{
continue;
}
result.Add(openCliCommand);
}
return result;
}
private List<OpenCliArgument> CreateArguments(IEnumerable<CommandArgument>? arguments)
{
var result = new List<OpenCliArgument>();
if (arguments == null)
{
return result;
}
foreach (var argument in arguments.OrderBy(x => x.Position))
{
var metadata = default(List<OpenCliMetadata>);
if (argument.ParameterType != typeof(void) &&
argument.ParameterType != typeof(bool))
{
metadata =
[
new OpenCliMetadata { Name = "ClrType", Value = argument.ParameterType.ToCliTypeString(), },
];
}
result.Add(new OpenCliArgument
{
Name = argument.Value,
Required = argument.IsRequired,
Arity = new OpenCliArity
{
// TODO: Look into this
Minimum = 1,
Maximum = 1,
},
Description = argument.Description,
Hidden = argument.IsHidden,
Metadata = metadata,
AcceptedValues = null,
Group = null,
});
}
return result;
}
private List<OpenCliOption> CreateOptions(IEnumerable<CommandOption>? options)
{
var result = new List<OpenCliOption>();
if (options == null)
{
return result;
}
foreach (var option in options.OrderBy(o => o.GetOptionName(), StringComparer.OrdinalIgnoreCase))
{
var arguments = new List<OpenCliArgument>();
if (option.ParameterType != typeof(void) &&
option.ParameterType != typeof(bool))
{
arguments.Add(new OpenCliArgument
{
Name = option.ValueName ?? "VALUE",
Required = !option.ValueIsOptional,
Arity = new OpenCliArity
{
// TODO: Look into this
Minimum = option.ValueIsOptional
? 0
: 1,
Maximum = 1,
},
AcceptedValues = null,
Group = null,
Hidden = null,
Metadata =
[
new OpenCliMetadata
{
Name = "ClrType",
Value = option.ParameterType.ToCliTypeString(),
},
],
});
}
var optionMetadata = default(List<OpenCliMetadata>);
if (arguments.Count == 0 && option.ParameterType != typeof(void) &&
option.ParameterType != typeof(bool))
{
optionMetadata =
[
new OpenCliMetadata { Name = "ClrType", Value = option.ParameterType.ToCliTypeString(), },
];
}
var (optionName, optionAliases) = GetOptionNames(option);
result.Add(new OpenCliOption
{
Name = optionName,
Required = option.IsRequired,
Aliases = [..optionAliases.OrderBy(str => str)],
Arguments = arguments,
Description = option.Description,
Group = null,
Hidden = option.IsHidden,
Recursive = option.IsShadowed, // TODO: Is this correct?
Metadata = optionMetadata,
});
}
return result;
}
private static (string Name, HashSet<string> Aliases) GetOptionNames(CommandOption option)
{
var name = GetOptionName(option);
var aliases = new HashSet<string>();
if (option.LongNames.Count > 0)
{
foreach (var alias in option.LongNames.Skip(1))
{
aliases.Add("--" + alias);
}
foreach (var alias in option.ShortNames)
{
aliases.Add("-" + alias);
}
}
else
{
foreach (var alias in option.LongNames)
{
aliases.Add("--" + alias);
}
foreach (var alias in option.ShortNames.Skip(1))
{
aliases.Add("-" + alias);
}
}
return (name, aliases);
}
private static string GetOptionName(CommandOption option)
{
return option.LongNames.Count > 0
? "--" + option.LongNames[0]
: "-" + option.ShortNames[0];
}
}

View File

@@ -2,7 +2,7 @@ namespace Spectre.Console.Cli;
[Description("Displays the CLI library version")]
[SuppressMessage("Performance", "CA1812: Avoid uninstantiated internal classes")]
internal sealed class VersionCommand : Command<VersionCommand.Settings>
internal sealed class VersionCommand : Command, IBuiltInCommand
{
private readonly IAnsiConsole _writer;
@@ -11,11 +11,7 @@ internal sealed class VersionCommand : Command<VersionCommand.Settings>
_writer = configuration.Settings.Console.GetConsole();
}
public sealed class Settings : CommandSettings
{
}
public override int Execute(CommandContext context, Settings settings)
public override int Execute(CommandContext context)
{
_writer.MarkupLine(
"[yellow]Spectre.Cli[/] version [aqua]{0}[/]",

View File

@@ -2,7 +2,7 @@ namespace Spectre.Console.Cli;
[Description("Generates an XML representation of the CLI configuration.")]
[SuppressMessage("Performance", "CA1812: Avoid uninstantiated internal classes")]
internal sealed class XmlDocCommand : Command<XmlDocCommand.Settings>
internal sealed class XmlDocCommand : Command, IBuiltInCommand
{
private readonly CommandModel _model;
private readonly IAnsiConsole _writer;
@@ -13,11 +13,7 @@ internal sealed class XmlDocCommand : Command<XmlDocCommand.Settings>
_writer = configuration.Settings.Console.GetConsole();
}
public sealed class Settings : CommandSettings
{
}
public override int Execute(CommandContext context, Settings settings)
public override int Execute(CommandContext context)
{
_writer.Write(Serialize(_model), Style.Plain);
return 0;

View File

@@ -5,6 +5,7 @@ internal static class CliConstants
public const string DefaultCommandName = "__default_command";
public const string True = "true";
public const string False = "false";
public const string DumpHelpOpenCliOption = "--help-dump-opencli";
public static string[] AcceptedBooleanValues { get; } = new string[]
{
@@ -18,5 +19,6 @@ internal static class CliConstants
public const string Version = "version";
public const string XmlDoc = "xmldoc";
public const string Explain = "explain";
public const string OpenCli = "opencli";
}
}

View File

@@ -0,0 +1,13 @@
#if NETSTANDARD2_0
namespace System.IO;
// Polyfills needed for OpenCli.
// This can be removed once me migrate over to the Polyfill library.
internal static class OpenCliExtensions
{
public static Task<string> ReadToEndAsync(this StreamReader reader, CancellationToken cancellationToken)
{
return reader.ReadToEndAsync();
}
}
#endif

View File

@@ -16,4 +16,19 @@ internal static class TypeExtensions
return false;
}
// Taken from https://github.com/dotnet/sdk/blob/main/src/Cli/Microsoft.DotNet.Cli.Utils/Extensions/TypeExtensions.cs#L15
// Licensed under MIT
public static string ToCliTypeString(this Type type)
{
var typeName = type.FullName ?? string.Empty;
if (!type.IsGenericType)
{
return typeName;
}
var genericTypeName = typeName.Substring(0, typeName.IndexOf('`'));
var genericTypes = string.Join(", ", type.GenericTypeArguments.Select(generic => generic.ToCliTypeString()));
return $"{genericTypeName}<{genericTypes}>";
}
}

View File

@@ -2,6 +2,16 @@ namespace Spectre.Console.Cli;
internal static class CommandInfoExtensions
{
public static IEnumerable<CommandArgument>? GetArguments(this CommandInfo? command)
{
return command?.Parameters.OfType<CommandArgument>();
}
public static IEnumerable<CommandOption>? GetOptions(this CommandInfo? command)
{
return command?.Parameters.OfType<CommandOption>();
}
public static bool HaveParentWithOption(this CommandInfo command, CommandOption option)
{
var parent = command?.Parent;

View File

@@ -38,7 +38,7 @@ internal abstract class CommandParameter : ICommandParameterInfo, ICommandParame
DefaultValue = defaultValue;
PairDeconstructor = deconstructor;
ValueProvider = valueProvider;
Validators = new List<ParameterValidationAttribute>(validators ?? Array.Empty<ParameterValidationAttribute>());
Validators = new List<ParameterValidationAttribute>(validators ?? []);
IsRequired = required;
IsHidden = isHidden;
}

View File

@@ -9,6 +9,7 @@ global using System.IO;
global using System.Linq;
global using System.Reflection;
global using System.Text;
global using System.Threading;
global using System.Threading.Tasks;
global using System.Xml;
global using Spectre.Console.Cli.Help;

View File

@@ -3,11 +3,11 @@
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0;netstandard2.0</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>
<PropertyGroup>
<IsAotCompatible Condition="'$(TargetFramework)' != 'netstandard2.0'">false</IsAotCompatible>
<IsTrimmable>false</IsTrimmable>
<DefineConstants>$(DefineConstants);OPENCLI_VISIBILITY_INTERNAL</DefineConstants>
</PropertyGroup>
<ItemGroup Label="REMOVE THIS">
<InternalsVisibleTo Include="Spectre.Console.Cli.Tests"/>
</ItemGroup>
@@ -18,6 +18,7 @@
</PropertyGroup>
<ItemGroup Label="Dependencies">
<PackageReference Include="OpenCli.Sources" />
<PackageReference Include="PolySharp">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

View File

@@ -28,4 +28,4 @@
<Project Path="Spectre.Console.Testing/Spectre.Console.Testing.csproj" />
<Project Path="Spectre.Console/Spectre.Console.csproj" />
<Project Path="Tests/Spectre.Console.Tests/Spectre.Console.Tests.csproj" />
</Solution>
</Solution>

View File

@@ -3,16 +3,17 @@ namespace Spectre.Console.Tests;
public static class Constants
{
public static string[] VersionCommand { get; } =
new[]
{
CliConstants.Commands.Branch,
CliConstants.Commands.Version,
};
[
CliConstants.Commands.Branch,
CliConstants.Commands.Version
];
public static string[] XmlDocCommand { get; } =
new[]
{
CliConstants.Commands.Branch,
CliConstants.Commands.XmlDoc,
};
[
CliConstants.Commands.Branch,
CliConstants.Commands.XmlDoc
];
public static string[] OpenCliOption { get; } =
[CliConstants.DumpHelpOpenCliOption];
}

View File

@@ -0,0 +1,190 @@
{
"opencli": "0.1-draft",
"info": {
"title": "my-app",
"version": "1.2.3"
},
"commands": [
{
"name": "animals",
"commands": [
{
"name": "cat",
"options": [
{
"name": "--agility",
"required": false,
"arguments": [
{
"name": "VALUE",
"required": true,
"arity": {
"minimum": 1,
"maximum": 1
},
"metadata": [
{
"name": "ClrType",
"value": "System.Int32"
}
]
}
],
"description": "The agility between 0 and 100.",
"recursive": false,
"hidden": false
},
{
"name": "--alive",
"required": false,
"aliases": [
"--not-dead",
"-a"
],
"description": "Indicates whether or not the animal is alive.",
"recursive": false,
"hidden": false
},
{
"name": "--name",
"required": false,
"aliases": [
"--pet-name",
"-n",
"-p"
],
"arguments": [
{
"name": "VALUE",
"required": true,
"arity": {
"minimum": 1,
"maximum": 1
},
"metadata": [
{
"name": "ClrType",
"value": "System.String"
}
]
}
],
"recursive": false,
"hidden": false
}
],
"arguments": [
{
"name": "LEGS",
"required": false,
"arity": {
"minimum": 1,
"maximum": 1
},
"description": "The number of legs.",
"hidden": false,
"metadata": [
{
"name": "ClrType",
"value": "System.Int32"
}
]
}
],
"hidden": false,
"examples": []
},
{
"name": "dog",
"options": [
{
"name": "--alive",
"required": false,
"aliases": [
"--not-dead",
"-a"
],
"description": "Indicates whether or not the animal is alive.",
"recursive": false,
"hidden": false
},
{
"name": "--good-boy",
"required": false,
"aliases": [
"-g"
],
"recursive": false,
"hidden": false
},
{
"name": "--name",
"required": false,
"aliases": [
"--pet-name",
"-n",
"-p"
],
"arguments": [
{
"name": "VALUE",
"required": true,
"arity": {
"minimum": 1,
"maximum": 1
},
"metadata": [
{
"name": "ClrType",
"value": "System.String"
}
]
}
],
"recursive": false,
"hidden": false
}
],
"arguments": [
{
"name": "LEGS",
"required": false,
"arity": {
"minimum": 1,
"maximum": 1
},
"description": "The number of legs.",
"hidden": false,
"metadata": [
{
"name": "ClrType",
"value": "System.Int32"
}
]
},
{
"name": "AGE",
"required": true,
"arity": {
"minimum": 1,
"maximum": 1
},
"hidden": false,
"metadata": [
{
"name": "ClrType",
"value": "System.Int32"
}
]
}
],
"description": "The dog command.",
"hidden": false,
"examples": []
}
],
"hidden": false,
"examples": []
}
]
}

View File

@@ -0,0 +1,33 @@
namespace Spectre.Console.Tests.Unit.Cli;
public sealed partial class CommandAppTests
{
[ExpectationPath("OpenCli")]
public sealed partial class OpenCli
{
[Fact]
[Expectation("Generate")]
public Task Should_Output_OpenCli_Description()
{
// Given
var fixture = new CommandAppTester();
fixture.Configure(config =>
{
config.SetApplicationName("my-app");
config.SetApplicationVersion("1.2.3");
config.AddBranch("animals", animals =>
{
animals.AddCommand<DogCommand>("dog");
animals.AddCommand<CatCommand>("cat");
});
});
// When
var result = fixture.Run(Constants.OpenCliOption);
// Then
return Verifier.Verify(result.Output);
}
}
}