Cysharp / ConsoleAppFramework

Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.
MIT License
1.62k stars 93 forks source link

Proposal: always handle values with dashes as parameter names #79

Closed zadykian closed 2 years ago

zadykian commented 2 years ago

Proposal

Change behaviour of ConsoleAppEngine.TryGetInvokeArguments method to always handle values starting with dashes as parameter names but not values.

In this case it would be required to pass value starting with dashes wrapped into quotes. For example:

MyApp.Exe command --some-arg "--arg-value-with-leading-dashes"

Motivation

Current parsing mechanism doesn’t provide correct error messages in case if one of multiple parameters is passed without value. For example:

App definition:

public class CommandTests_Single_Two_Required : ConsoleAppBase
{
    [RootCommand]
    public void Hello(string firstName, string lastName) => Console.WriteLine($"Hello {firstName} {lastName}");
}

Input:

MyApp.Exe --first-name --last-name "TestLastName"

Output:

Required parameter "last-name" not found in argument. args: --first-name --last-name TestLastName

So, "--last-name" is parsed as value of --first-name parameter

Expecting output:

Value for parameter "first-name" is not provided.
zadykian commented 2 years ago

@neuecc what do you think? I'm ready to implement this, but it's definitely a breaking change for some cases. Maybe default behaviour should be leaved untouched with ability to enable strict parsing via ConsoleAppOptions

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.