Skip to content

Displaying help text with fluent syntax? #39

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

Closed
ericnewton76 opened this issue Nov 4, 2017 · 2 comments
Closed

Displaying help text with fluent syntax? #39

ericnewton76 opened this issue Nov 4, 2017 · 2 comments
Labels

Comments

@ericnewton76
Copy link
Member

Issue by jawn
Wednesday Aug 12, 2015 at 08:58 GMT
Originally opened as gsscoder/commandline#223


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.

@ericnewton76
Copy link
Member Author

Comment by gsscoder
Wednesday Aug 12, 2015 at 13:23 GMT


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.

@moh-hassan
Copy link
Collaborator

Closed for age.

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