CommandLineUtils icon indicating copy to clipboard operation
CommandLineUtils copied to clipboard

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

Open djpirra opened this issue 4 years ago • 1 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?

djpirra avatar Oct 12 '21 15:10 djpirra

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

natemcmaster avatar Oct 13 '21 03:10 natemcmaster

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.

github-actions[bot] avatar Oct 14 '22 02:10 github-actions[bot]

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.

github-actions[bot] avatar Oct 29 '22 02:10 github-actions[bot]