natemcmaster / CommandLineUtils

Command line parsing and utilities for .NET

Home Page:https://natemcmaster.github.io/CommandLineUtils/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to have options using boolean values and how to pass them through command line?

djpirra opened this issue · comments

Hi everyone,

I am using this library for the first time, and I tried to create a boolean option with a default value of true, like this:

[Option("-h|--header", Description = "Specify if source file contains header row")] private bool HasHeader { get; } = true;

When I am trying to pass the parameter I am getting the following message:
"Unexpected value 'true' for Option 'header'"

I have tried passing the parameter on powershell command line like this:
--header:true
-h true
-h $true
-h 1
-h=true

Nothing seems to work out.

Anyone have achieved this?

Try setting the option type. [Option("-h|--header", CommandOptionType.SingleValue, ... By default, bool is treated as CommandOptionType.NoValue.

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.

Closing due to inactivity.
If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.