Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default values are being ignored - regression #70

Closed
kjbartel opened this issue May 8, 2020 · 2 comments
Closed

Default values are being ignored - regression #70

kjbartel opened this issue May 8, 2020 · 2 comments
Labels

Comments

@kjbartel
Copy link

kjbartel commented May 8, 2020

After upgrading to latest version (3.0.20), parsing now ignores the default value if the argument isn't defined in the arguments list. It instead will use the default value for the type. e.g. 0 for an int or enum.

public enum OptionsFlag
{
    O1, O2, O3
}

public class Options
{
    [ValueArgument(typeof( OptionsFlag), 'f', "flag", DefaultValue = OptionsFlag.O3)]
    public OptionsFlag Flag = OptionsFlag.O3;

    public static Options ParseOptions(string[] args)
    {
        var options = new Options();
        Debug.Assert(options.Flag == OptionsFlag.O3);
        var parser = new CommandLineParser.CommandLineParser();
        parser.ExtractArgumentAttributes(options);

        parser.ParseCommandLine(args);
        // This will fail when args is empty! it has been set to O1
        Debug.Assert(options.Flag == OptionsFlag.O3);

        return options;
    }
}
@kjbartel
Copy link
Author

kjbartel commented May 8, 2020

Ok this isn't just enum. All default values are being ignored. For example an int with a default value of -1 will be changed to 0.

@kjbartel kjbartel changed the title Enum parsing ignore default - regression Default values are being ignored - regression May 8, 2020
@StefH StefH added the bug label May 8, 2020
@StefH
Copy link
Collaborator

StefH commented Dec 1, 2020

#68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants