Skip to content

Argument validator did not run because of GetValue within a Command validator #2607

@NPatch

Description

@NPatch

Not sure if this is a bug, but it's confusing.

I have an Argument<string[]> inputArg which has a validator and this argument is on a command which also has a validator. The Command Validator was calling commandResult.GetResult(inputArg).GetValue<string[]>(inputArg) within. The command line is "command asdf". The argument's validator is expecting one specific string word or 1 or more numbers.

The argument's validator was not being called. I moved through parsing etc and on to validation using the debugger and I noticed that at some point a conversion result was being produced and there's a part where validation is about to be called on that argument, but it doesn't because the code does sth like:
_conversionResult ??= ValidateAndConvert(..).

So the argument's validator doesn't trigger. Afterwards I noticed that _conversionResult is being set when I call GetValue.

If I change the GetValue to commandResult.GetResult(inputArg).Tokens, this doesn't happen.

That said, there's not enough documentation on Validators and the only example on the MS docs uses GetValue, so a user will likely default to that, even if there's other examples buried in the Github Issues that uses Tokens instead.

Is this intentional or a bug?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions