commandline icon indicating copy to clipboard operation
commandline copied to clipboard

bool value is not support

Open dashenxian opened this issue 1 year ago • 3 comments

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 avatar Feb 22 '24 08:02 dashenxian

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

dashenxian avatar Feb 22 '24 08:02 dashenxian

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

VewDev avatar Feb 22 '24 10:02 VewDev

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

dashenxian avatar Feb 26 '24 02:02 dashenxian