Skip to content

Required bool is not seen #413

@ChangePlaces

Description

@ChangePlaces

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

-version 1.9.71 from nuget

Activity

nemec

nemec commented on Feb 11, 2017

@nemec
Collaborator

Hi @ChangePlaces what does your options class look like?

ChangePlaces

ChangePlaces commented on Feb 11, 2017

@ChangePlaces
Author

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));
    }

}
nemec

nemec commented on Feb 11, 2017

@nemec
Collaborator

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.

ChangePlaces

ChangePlaces commented on Feb 11, 2017

@ChangePlaces
Author

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

nemec commented on Feb 12, 2017

@nemec
Collaborator

Yep! You could use a string, too, and implement your own validation if you wanted, but still have to deal with strings :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nemec@ChangePlaces

        Issue actions

          Required bool is not seen · Issue #413 · gsscoder/commandline