Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option shortname does not allow bool parameter to be supplied as false #125

Open
sorenhnielsen opened this issue Feb 20, 2024 · 0 comments

Comments

@sorenhnielsen
Copy link

Trying to add an option of type bool with a shortname.
The fullname of the option parse the bool parameter correct while the shortname is always true.


Example from Samples, modified

using Cocona;

namespace CoconaSample.GettingStarted.TypicalSimpleApp;

class Program
{
static void Main(string[] args)
{
CoconaApp.Run(args);
}

[Command(Description = "This is a sample application")]
public void Hello([Argument(Description = "Your name")] string name, [Option("upper", shortNames: ['u'], Description = "Print a name converted to upper-case.")] bool toUpperCase = true)
{
    Console.WriteLine($"Hello {(toUpperCase ? name.ToUpper() : name)}!");
}

}

Changed Option to have a Name 'upper' and have a default value of true.

Usage:
CoconaSample.GettingStarted.TypicalSimpleApp.exe "name" --upper=true
returns: Hello NAME

CoconaSample.GettingStarted.TypicalSimpleApp.exe "name" --upper=false
returns: Hello name

CoconaSample.GettingStarted.TypicalSimpleApp.exe "name" -u true
return Hello NAME

CoconaSample.GettingStarted.TypicalSimpleApp.exe "name" -u false
return Hello NAME <-- would expect 'Hello name' here

If seems like Shortnames just returns bool based on if the parameter is there, meaning it is not possible to supply false with the parameter.

Would expect the shortname to allow the parameter to be set to true/false depending on what is supplied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant