commandlineparser / commandline

The best C# command line parser that brings standardized *nix getopt style, for .NET. Includes F# support
MIT License
4.46k stars 473 forks source link

bool value is not support #916

Open dashenxian opened 4 months ago

dashenxian commented 4 months ago

code:

static void Main(string[] args)
{
    args = new[] {
         "--y-up-to-z-up", "false",
         "E:\\0.obj",
         "E:\\DeskTop\\output1",
         };
    var result=Parser.Default.ParseArguments<Options>(args);
    result.Value.Dump();
}
public class Options
{
    [Value(0, MetaName = "Input", Required = true, HelpText = "Input OBJ file.")]
    public string Input { get; set; }

    [Value(1, MetaName = "Output", Required = true, HelpText = "Output folder.")]
    public string Output { get; set; }

    [Option('t',"y-up-to-z-up", Required = false, HelpText = "Convert the upward Y-axis ",Default=true)]
    public bool YUpToZUp { get; set; }
}

YUpToZUp is not right,and input will be override by YUpToZUp's value image

dashenxian commented 4 months ago

if YUpToZUp is bool? type,it will be right;

     [Option('t',"y-up-to-z-up", Required = false, HelpText = "Convert the upward Y-axis ",Default=true)]
--   public bool YUpToZUp { get; set; }
++   public bool? YUpToZUp { get; set; }

image

je-sendra commented 4 months ago

bool parameters are a Switch Option. If the option is passed to the command line, it will always be true.

For your desired behavior (being able to pass it and set it to false) you need to declare it as a bool?.

For documentation about this, see:

https://github.com/commandlineparser/commandline/wiki/CommandLine-Grammar#switch-option

dashenxian commented 4 months ago

bool parameters are a Switch Option. If the option is passed to the command line, it will always be true.

For your desired behavior (being able to pass it and set it to false) you need to declare it as a bool?.

For documentation about this, see:

https://github.com/commandlineparser/commandline/wiki/CommandLine-Grammar#switch-option

Thanks