You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a config with a required bool field, and I get the error that it isn't inlcuded, when it clearly is. I have tried --thefield=false / --thefield=0 / --thefield=f
The single bool --usecache isn't recognised. I've stripped additional comments and the like.
public class Config
{
[CommandLine.Option("countsfile",Required=true,DefaultValue ="counts.txt",HelpText ="Where to write the reported search result counts.")]
public string CountsFileName { get; set; }
[CommandLine.Option("inputfile", Required = true, HelpText = "The input file.")]
public string InputFile { get; set; }
[CommandLine.Option("outputdir", Required = true, DefaultValue = "searches", HelpText = "Where to write the output")]
public string OutputDirectory { get; set; }
[CommandLine.Option("usecache", Required = true, DefaultValue = false, HelpText = "should the downloaded pages be written to a cache?")]
public bool UseFileCache { get; set; }
[CommandLine.Option("cachedir", Required = false, HelpText = "the location of where to write the cache of downloaded files")]
public string FileCacheDirectory { get; set; }
[CommandLine.Option("country", Required = true, HelpText = "Which site should we search")]
public UtilityLibrary.CountryHelpers.Country.CountryCode CountryCode { get; set; }
[CommandLine.Option("offset", Required = false, DefaultValue = 0, HelpText = "How many chosen lines to skip? ")]
public int Offset { get; set; }
[CommandLine.Option("maxresults", Required = true, HelpText = "What is the max count pull results for?")]
public int MaxResultCount { get; set; }
[CommandLine.Option("interval", Required = true, HelpText = "how many suggestions should be skipped")]
public int Interval { get; set; }
[CommandLine.ParserState]
public CommandLine.IParserState LastParserState { get; set; }
[CommandLine.HelpOption]
public string GetUsage()
{
return CommandLine.Text.HelpText.AutoBuild(this,
(CommandLine.Text.HelpText current) => CommandLine.Text.HelpText.DefaultParsingErrorsHandler(this, current));
}
}
Thanks, I understand the problem now. Boolean options do not support "values" aka --opt=true or --opt=false, it's simply false if not provided and true if provided.
e.g.
myprog.exe --usecache
will set it to true. Leaving the value off will set it to false. As you've noticed, that doesn't play well with Required options.
The 1.9.* branch not under active development, and therefore will not be fixed, but the author has indicated in #133 and #158 that it's something we want in 2.x.
If you don't mind, I'm going to close this issue but feel free to click the "subscribe" button on those other two to get a notice when there is movement on the feature.
ahh thanks for getting back to me. i understand now! it's at least some relief to understand the logic behind it! I suppose a quick (untested) workaround may be to use an int instead of bool? 0 to indicate false and vice versa.
Activity
nemec commentedon Feb 11, 2017
Hi @ChangePlaces what does your options class look like?
ChangePlaces commentedon Feb 11, 2017
The single bool --usecache isn't recognised. I've stripped additional comments and the like.
nemec commentedon Feb 11, 2017
Thanks, I understand the problem now. Boolean options do not support "values" aka
--opt=true
or--opt=false
, it's simply false if not provided and true if provided.e.g.
will set it to true. Leaving the value off will set it to false. As you've noticed, that doesn't play well with
Required
options.The 1.9.* branch not under active development, and therefore will not be fixed, but the author has indicated in #133 and #158 that it's something we want in 2.x.
If you don't mind, I'm going to close this issue but feel free to click the "subscribe" button on those other two to get a notice when there is movement on the feature.
ChangePlaces commentedon Feb 11, 2017
ahh thanks for getting back to me. i understand now! it's at least some relief to understand the logic behind it! I suppose a quick (untested) workaround may be to use an int instead of bool? 0 to indicate false and vice versa.
nemec commentedon Feb 12, 2017
Yep! You could use a string, too, and implement your own validation if you wanted, but still have to deal with strings :(