cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.85k stars 724 forks source link

Upgrade Spectre.Console to v0.46.0 #4138

Closed FrankRay78 closed 1 year ago

FrankRay78 commented 1 year ago

Prerequisites

Cake runner

Cake Frosting

Cake version

Latest as of 4 April 2023 (commit 7ad0f4865484a733d26f3bce2e70bfe968d968d4)

Operating system

Windows

Operating system architecture

64-Bit

CI Server

N/A

What are you seeing?

Upgrading the NuGet package reference to spectre.console from 0.45.0 to 0.46.0, compiles ok but results in the following failed unit tests:

image

What is expected?

All green, as per running with spectre.console 0.45.0

Steps to Reproduce

Upgrade NuGet package references to spectre.console to 0.46.0

Output log

N/A - see screenshot above

FrankRay78 commented 1 year ago

Please assign this issue to me @augustoproiete. I came across it when upgrading the package references because I wanted to test some new features in spectre.console 0.46.0

devlead commented 1 year ago

Spectre Console had a breaking change in with the examples, could be this that affects Frosting. try changing https://github.com/cake-build/cake/blob/7ad0f4865484a733d26f3bce2e70bfe968d968d4/src/Cake.Frosting/CakeHost.cs#L93 and https://github.com/cake-build/cake/blob/7ad0f4865484a733d26f3bce2e70bfe968d968d4/src/Cake/Program.cs#L61 to

config.AddExample(Array.Empty<string>());

I've assigned the issue to you.

FrankRay78 commented 1 year ago

Your suggestion fixes the issue @devlead. Interestingly, it's the call to config.ValidateExamples(); that's causing the Frosting tests to fail. Once I turn on the following, config.PropagateExceptions(); the true nature of the issue becomes clear:

Message: 
Spectre.Console.Cli.CommandConfigurationException : Validation of examples failed.
---- Spectre.Console.Cli.CommandParseException : Unknown command ''.

  Stack Trace: 
CommandModelValidator.ValidateExamples(CommandModel model, CommandAppSettings settings) line 155
CommandModelValidator.Validate(CommandModel model, CommandAppSettings settings) line 42
CommandModelBuilder.Build(IConfiguration configuration) line 40

Basically, the following example config.AddExample(new[] { string.Empty }); passes spectre one argument, an empty string, which is then validated against the available commands, unsuccessfully.

The above applies to Frosting, I believe the DefaultCommand examples in the Cake project validate successfully because DefaultCommandSettings additionally includes a Script argument, which Frosting doesn't.

namespace Cake.Commands
{
    public sealed class DefaultCommandSettings : CommandSettings
    {
        [CommandArgument(0, "[SCRIPT]")]
        [Description("The Cake script. Defaults to [grey]build.cake[/]")]
        [TypeConverter(typeof(Cli.FilePathConverter))]
        [DefaultValue("build.cake")]
        public FilePath Script { get; set; }
cake-build-bot commented 1 year ago

:tada: This issue has been resolved in version v3.1.0 :tada:

The release is available on:

Your GitReleaseManager bot :package::rocket: