Skip to content

Is CommandLineApplication.Parse supposed to trigger validation? #149

@thomaslevesque

Description

@thomaslevesque

I'm using CommandLineUtils to parse command line options, but I don't want to use the library's execution engine, because I don't want to refactor the existing code to fit that model. So I'm using the Parse method like this:

        var app = new CommandLineApplication(throwOnUnexpectedArg: false);
        var configurationOption = app.Option<string>(
            "-c|--configuration",
            "The build configuration",
            CommandOptionType.SingleValue,
            option => option.Accepts(builder => builder.Values("Debug", "Release")));
        app.Parse(args);
        var configuration = configurationOption.HasValue() ? configurationOption.Value() : "Release";

However, option.Accepts(builder => builder.Values("Debug", "Release")) seems to have no effect. It looks like validation isn't run. Is this the expected behavior? If not, how could I achieve what I'm trying to do?

I know I could just check the value manually, but I was hoping to take advantage of CommandLineUtils' validation mechanism.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions