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: Late Binding or SetDefault method #93

Open
caverna opened this issue Jan 15, 2018 · 1 comment
Open

Feature: Late Binding or SetDefault method #93

caverna opened this issue Jan 15, 2018 · 1 comment

Comments

@caverna
Copy link

caverna commented Jan 15, 2018

Hi! I have this situation:

private DateTime _firstDate;
private DateTime _lastDate;

private FluentCommandLineParser CreateParser()
{
    var parser = new FluentCommandLineParser();

    parser.SetupHelp("?", "help")
        .Callback(text => Console.WriteLine(text));

    parser
        .Setup<DateTime>('d', "FirstDate")
        .Callback(value => _firstDate = value.Date)
        .SetDefault(DateTime.Today);

    parser
        .Setup<DateTime>('l', "LastDate")
        .Callback(value => _lastDate = value)
        .SetDefault(_firstDate); // this should be a kind of 'late binding'!

    return parser;
}

The behaviour that I expect would be, when an user doesn't provide 'L', just get the 'D' value.

My current workaround is:

var result = parser.Parse(args);
if (_lastDate == new DateTime())
    _lastDate = _firstDate;
@siywilliams
Copy link
Member

Hi @caverna

I can't see your proposed "late-binding" being required in many scenarios, however it might be easy to add a generic func overload for the SetDefault method which can be alternatively used in your particular scenario.

So for example,

parser.Setup<DateTime>('l', "LastDate")
      .Callback(value => _lastDate = value)
      .SetDefault(() => _firstDate); // 'late binding' achieved using new overload

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

No branches or pull requests

2 participants