Skip to content

Display help when no option is specified #286

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
nicolasr75 opened this issue Feb 5, 2016 · 4 comments
Open

Display help when no option is specified #286

nicolasr75 opened this issue Feb 5, 2016 · 4 comments
Labels

Comments

@nicolasr75
Copy link

Using version 2.0:
When the user does not specify any option, I would like to display the same help screen that is automatically shown when the user specifies --help.
I have a very simple program and would like to use as much default behavior as possible. I am using only a few options and this is the code I am using for parsing:

var parserResult = Parser.Default.ParseArguments<CommandlineOptions>(args)

if (parserResult.Tag == ParserResultType.Parsed)
{
    CommandlineOptions options = ((Parsed<CommandlineOptions>)parserResult).Value;

    if(options....)
    {

    }
    ...
    else  //no options specified
    {
        Console.WriteLine(CommandLine.Text.HelpText.AutoBuild(parserResult)); //***
    }       
}

However, the line marked with *** does not work because it expects a NotParsed instance. How could I generate the help output?

@alexanderfast
Copy link
Collaborator

Related to #281.

@nemec
Copy link
Collaborator

nemec commented Mar 23, 2016

@nicolasr75 see the related question for how to do it without needing a parserResult. Let me know if it works for you!

@nicolasr75
Copy link
Author

I put your snippet into my code but it does not compile because of
"TypeInfo does not contain a definition for 'Create'"
Any idea?

@nemec
Copy link
Collaborator

nemec commented Mar 24, 2016

Upon further investigation, the TypeInfo class is actually a custom (internal) class, not referring to System.Reflection.TypeInfo at all. Sorry, I guess that doesn't work.

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

3 participants