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

Feature proposal: Provide a way to specify arguments object factory method #64

Open
KonstantinRyazantsev opened this issue Apr 4, 2016 · 1 comment

Comments

@KonstantinRyazantsev
Copy link

In version 1.4.3, FluentCommandLineParser<TBuildType> requires that TBuildType provides public parameterless constructor, using new() generic parameter constraint. Will be nice to have a way to use arguments object without public parameterless constructor. For instance, by introducing FluentCommandLineParser<TBuildType> constructor overload, which accepts Action<TBuildType> factory method. It can be used to better argument object incapsulation, by prohibiting its creation outside of argument object factory method. For example:

internal class StartupArguments
{
    public bool Argument1 { get; private set; }
    public bool Argument2 { get; private set; }
    public bool HelpCalled { get; set; }

    // I can't do it private now :(
    private StartupArguments()
    {
    }

    public static StartupArguments Parse(string[] args)
    {
        // Just creates arguments object
        var parser = new FluentCommandLineParser<StartupArguments>(() => new StartupArguments());

        // Setup here

        var parsingResult = parser.Parse(args);

        parser.Object.HelpCalled = parsingResult.HelpCalled;

        return parser.Object;
    }
}

Lovely lib, mate 👍

@siywilliams
Copy link
Member

Super idea @KonstantinRyazantsev I will look into adding this suggestion!

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

No branches or pull requests

2 participants