cake icon indicating copy to clipboard operation
cake copied to clipboard

Allow short argument names when using double dashed args

Open augustoproiete opened this issue 3 years ago • 11 comments

Background

Currently one-letter arguments are only supported with single-dashed arguments. e.g.

This works:

dotnet cake -a=5

Whereas this does not work (error: Invalid long option name)

dotnet cake --a=5

Proposal

This issue intends to make the necessary updates to allow short argument names when using double-dashed arguments.

Important

Cake uses Spectre.Console for parsing arguments, so there's a little bit of investigation needed to see if the fix can (and should) be done directly in Cake, of if it should be fixed upstream. If you discover that the fix doesn't belong in Cake, you'd need to send a PR to Spectre.Console and the fix in Cake would be just upgrading to a newer version of Spectre.Console.


Related:

augustoproiete avatar Mar 14 '21 22:03 augustoproiete

I will work on adding this!

MariaSolOs avatar Aug 30 '21 16:08 MariaSolOs

Great. Thanks for your interest @MariaSolOs.

Heads-up that we use Spectre.Console for parsing arguments, so there's a little bit of investigation needed to see if the fix can (and should) be done directly in Cake, of if it should be fixed upstream. If you discover that the fix doesn't belong in Cake, you'd need to send a PR to Spectre.Console and the fix in Cake would be just upgrading to a newer version of Spectre.Console.

augustoproiete avatar Aug 30 '21 16:08 augustoproiete

Great, thank you for the heads-up @augustoproiete! I'll investigate and do what feels the most appropriate.

MariaSolOs avatar Aug 30 '21 16:08 MariaSolOs

@augustoproiete Question: Do we want this feature to only be supported with custom switches, or also with the built-in ones (eg: --d)?

MariaSolOs avatar Aug 30 '21 18:08 MariaSolOs

@MariaSolOs The goal is to support both for consistency.

That said, the team might be having a change of heart on this one and we'll discuss more tomorrow and get back to you here.

The reason is that there's a general desire to be compatible with GNU standard for command-line interfaces which might conflict with this issue.

I think it's better to hold off working on this for now until we get more consensus in the team.

In the meantime, if you'd like to work on similar issues, these would be good candidates:

augustoproiete avatar Aug 31 '21 01:08 augustoproiete

@augustoproiete no problem at all! In fact I think this is great since I want to get a better grasp of the codebase before working on my contribution. :)

MariaSolOs avatar Aug 31 '21 01:08 MariaSolOs

After fetching the upstream on my forked repo this morning, I ran the tests in build.sh again and encountered the following error:

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.80]     Cake.NuGet.Tests.Unit.NuGetModuleTests+TheRegisterMethod.Should_Register_The_NuGet_Load_Directive_Provider [SKIP]
  Skipped Cake.NuGet.Tests.Unit.NuGetModuleTests+TheRegisterMethod.Should_Register_The_NuGet_Load_Directive_Provider [1 ms]
[xUnit.net 00:00:00.88]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Native_Runtimes_Assemblies_If_CoreCLR [FAIL]
  Failed Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Native_Runtimes_Assemblies_If_CoreCLR [23 ms]
  Error Message:
   Assert.Equal() Failure
Expected: 1
Actual:   0
  Stack Trace:
     at Cake.NuGet.Tests.Unit.NuGetContentResolverTests.Addins.Should_Return_Native_Runtimes_Assemblies_If_CoreCLR() in /Users/mariasolano/git/cake/src/Cake.NuGet.Tests/Unit/NuGetContentResolverTests.cs:line 372
[xUnit.net 00:00:00.92]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Log_Warning_For_Files_Located_In_Root [SKIP]
[xUnit.net 00:00:00.92]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Files_When_Located_In_Root [SKIP]
[xUnit.net 00:00:00.95]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Runtimes_Assemblies_If_CoreCLR [FAIL]
[xUnit.net 00:00:00.95]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_From_Root_If_No_Compatible_Framework_Found [SKIP]
  Skipped Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Log_Warning_For_Files_Located_In_Root [1 ms]
  Skipped Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Files_When_Located_In_Root [1 ms]
  Failed Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Runtimes_Assemblies_If_CoreCLR [30 ms]
  Error Message:
   Assert.Equal() Failure
Expected: 1
Actual:   0
  Stack Trace:
     at Cake.NuGet.Tests.Unit.NuGetContentResolverTests.Addins.Should_Return_Runtimes_Assemblies_If_CoreCLR() in /Users/mariasolano/git/cake/src/Cake.NuGet.Tests/Unit/NuGetContentResolverTests.cs:line 353
  Skipped Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_From_Root_If_No_Compatible_Framework_Found [1 ms]
[xUnit.net 00:00:00.95]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Not_Return_Runtimes_Assemblies_If_Clr [SKIP]
  Skipped Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Not_Return_Runtimes_Assemblies_If_Clr [1 ms]
Results File: /Users/mariasolano/git/cake/artifacts/v1.3.0-null-args0001/test-results/Cake.NuGet.Tests_net5.0_TestResults.xml

Failed!  - Failed:     2, Passed:    67, Skipped:     5, Total:    74, Duration: 273 ms - /Users/mariasolano/git/cake/src/Cake.NuGet.Tests/bin/Release/net5.0/Cake.NuGet.Tests.dll (net5.0)

I haven't modified the code at all yet, so I'm a bit confused about why the tests are failing...

MariaSolOs avatar Aug 31 '21 14:08 MariaSolOs

@MariaSolOs It seems something might be missing in your environment. What do you see when you run dotnet --info from the folder where build.sh is located? (it seems /Users/mariasolano/git/cake/).

augustoproiete avatar Aug 31 '21 21:08 augustoproiete

Hmm there's something interesting potentially happening on MacOS, see this in the Bitrise MacOS logs too now

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:02.19]     Cake.NuGet.Tests.Unit.NuGetModuleTests+TheRegisterMethod.Should_Register_The_NuGet_Load_Directive_Provider [SKIP]
  Skipped Cake.NuGet.Tests.Unit.NuGetModuleTests+TheRegisterMethod.Should_Register_The_NuGet_Load_Directive_Provider [1 ms]
[xUnit.net 00:00:02.26]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Native_Runtimes_Assemblies_If_CoreCLR [FAIL]
[xUnit.net 00:00:02.30]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Log_Warning_For_Files_Located_In_Root [SKIP]
[xUnit.net 00:00:02.30]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Files_When_Located_In_Root [SKIP]
  Failed Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Native_Runtimes_Assemblies_If_CoreCLR [29 ms]
  Error Message:
   Assert.Equal() Failure
Expected: 1
Actual:   0
  Stack Trace:
     at Cake.NuGet.Tests.Unit.NuGetContentResolverTests.Addins.Should_Return_Native_Runtimes_Assemblies_If_CoreCLR() in /Users/vagrant/git/src/Cake.NuGet.Tests/Unit/NuGetContentResolverTests.cs:line 372
  Skipped Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Log_Warning_For_Files_Located_In_Root [1 ms]
  Skipped Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Files_When_Located_In_Root [1 ms]
[xUnit.net 00:00:02.33]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Runtimes_Assemblies_If_CoreCLR [FAIL]
[xUnit.net 00:00:02.33]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_From_Root_If_No_Compatible_Framework_Found [SKIP]
[xUnit.net 00:00:02.33]     Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Not_Return_Runtimes_Assemblies_If_Clr [SKIP]
  Failed Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_Runtimes_Assemblies_If_CoreCLR [26 ms]
  Error Message:
   Assert.Equal() Failure
Expected: 1
Actual:   0
  Stack Trace:
     at Cake.NuGet.Tests.Unit.NuGetContentResolverTests.Addins.Should_Return_Runtimes_Assemblies_If_CoreCLR() in /Users/vagrant/git/src/Cake.NuGet.Tests/Unit/NuGetContentResolverTests.cs:line 353
  Skipped Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Return_From_Root_If_No_Compatible_Framework_Found [1 ms]
  Skipped Cake.NuGet.Tests.Unit.NuGetContentResolverTests+Addins.Should_Not_Return_Runtimes_Assemblies_If_Clr [1 ms]
Results File: /Users/vagrant/git/artifacts/v1.3.0-alpha0011/test-results/Cake.NuGet.Tests_net5.0_TestResults.xml
Failed!  - Failed:     2, Passed:    67, Skipped:     5, Total:    74, Duration: 745 ms - /Users/vagrant/git/src/Cake.NuGet.Tests/bin/Release/net5.0/Cake.NuGet.Tests.dll (net5.0)
An error occurred when executing task 'Run-Unit-Tests'.

devlead avatar Sep 01 '21 07:09 devlead

Well @devlead at least it is a relief to know that it is not just me... @augustoproiete Running dotnet --info results in:

.NET SDK (reflecting any global.json):
 Version:   5.0.400
 Commit:    d61950f9bf

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.0
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/5.0.400/

Host (useful for support):
  Version: 5.0.9
  Commit:  208e377a53

.NET SDKs installed:
  2.1.301 [/usr/local/share/dotnet/sdk]
  3.1.412 [/usr/local/share/dotnet/sdk]
  5.0.400 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.18 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

MariaSolOs avatar Sep 01 '21 14:09 MariaSolOs

@MariaSolOs https://github.com/cake-build/cake/pull/3456 sorts the issue you're seeing

devlead avatar Sep 02 '21 18:09 devlead