Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command Line - bool argument doesn't work

I am trying to use bool argument in my console application. I'm using the CommandLineParser Package, but parser return error.

this is my option

    [Option("randomize", Required = false, DefaultValue = false, HelpText = "Enter \"true\" for the random selection")]
    public bool Randomize { get; set; }

argument: --randomize=true

I am using Parser.Default.ParseArguments

Any idea why this doesn't work?

like image 851
Tomáš Čičman Avatar asked Jun 10 '26 16:06

Tomáš Čičman


1 Answers

You don't need to add true or false as the argument value - CommandLineParser will just set the value to true if the argument is present.

So this will pass in a value of true:

--randomize

So if your application is called ParserApp the following passes true

ParserApp --randomize

While the below line will pass false

ParserApp

The Quick Start guide has an example for the usage of a boolean parameter.

like image 172
Matt Hogan-Jones Avatar answered Jun 13 '26 07:06

Matt Hogan-Jones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!