Skip to content

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

@KonstantinRyazantsev

Description

@KonstantinRyazantsev

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 👍

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions