j-maly / CommandLineParser

Command line parser. Declarative arguments support. Rich set of argument types (switches, enums, files, etc...). Mutually exclusive arguments validations.
MIT License
137 stars 30 forks source link

CheckMandatoryArguments not being evaluated #63

Closed tekgator closed 5 years ago

tekgator commented 5 years ago

CheckMandatoryArguments is set to false and a mandatory parameter is not passed will still throw an Exception. Looking at the code the CheckMandatoryArguments doesn't seem to be evaluated.

/// <summary>
/// Checks whether or non-optional arguments were defined on the command line. 
/// </summary>
/// <exception cref="MandatoryArgumentNotSetException"><see cref="Argument.Optional">Non-optional</see> argument not defined.</exception>
/// <seealso cref="CheckMandatoryArguments"/>, <seealso cref="Argument.Optional"/>
private void PerformMandatoryArgumentsCheck()
{
    _arguments.ForEach(delegate (Argument arg)
    {
        if (!arg.Optional && !arg.Parsed)
            throw new MandatoryArgumentNotSetException(string.Format(Messages.EXC_MISSING_MANDATORY_ARGUMENT, arg.Name), arg.Name);
    });
}
StefH commented 5 years ago

Solved in next version.