Skip to content

Displaying help text with fluent syntax? #223

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

Open
jawn opened this issue Aug 12, 2015 · 1 comment
Open

Displaying help text with fluent syntax? #223

jawn opened this issue Aug 12, 2015 · 1 comment
Labels

Comments

@jawn
Copy link

jawn commented Aug 12, 2015

Using the latest nuget of the version 2.0 pre-release, I can display help text like this:

var results = Parser.Default.ParseArguments<Options>(args)
  .WithParsed(opts => /* handle options here */)

if (results.Tag == ParserResultType.NotParsed)
{
  var helpText = HelpText.AutoBuild(results);
  Console.WriteLine(helpText);
}

Is there a way to do this within the fluent syntax?

Something like
var results = Parser.Default.ParseArguments(args)
.WithNotParsed(opts => Console.WriteLine(HelpText.AutoBuild()));
.WithParsed(opts => /* handle options here */)

Since AutoBuild() requires results, this can't be called within the fluent syntax. That's already logged as #88, however I would like to know whether a different solution is available.

@gsscoder
Copy link
Owner

Hi @jawn, happy you choose this library.

If you invoke the parser using default singleton like in posted sample, you don't need any call to AutoBuild(). This is because this instance is pre-configured with a ParserSettings.HelpWriter set to Console.Error and when this property has a value the help screen is automatically generated and displayed.

In this case just stay with the WithParsed and job is done.

If you want handle help text manually, there's various way to do it from using AutoBuild() to mixing various intermediate step to get whatever customization you want.

Any way a possible fluent version, could be an extension to ParserResult like result.AutoBuild()...

If this not helped, please let me know.

PS: If possible use ParserResult extension methods instead of manually checking Tag discriminator and cast the instance.

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