commandlineparser / commandlineparser/commandline

Support for custom dynamic help option for a single subcommand?

Aberta
#704 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
C#
Estrelas
4.8k
Forks
478
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

For all my current subcommands I am using the default help option (which is very nice btw!). I have 1 subcommand that I want the default help options to be turned off for so that I can display custom help code inside of my subcommand's OnExecute method:

```
protected bool HandleHelp(){
//TO DO: Check to see if --help was passed in and display custom help text to the console based on a Dictionary of known commands on current machine.
}
protected override async Task OnExecute(CommandLineApplication app)
{
try
{
//Load a list of all the available commands
BuildListOfKnownCommands();

//Check for help option and display help message for specific tool
if(HandleHelp()){
return 0;
}

//TO DO: Run command
return 0;
}
catch (Exception ex)
{
OnException(ex);
return 1;
}
```

Is there an easy way to do this?

I have tried adding a member to my subcommand like so:

```
[HelpOption("--help")]
public bool HelpRequested {get;set;} = false;
```

but this gives me the error message **"Multiple HelpOptionAttributes found. HelpOptionAttribute should only be used one per type, either on one property or type."**

I tried using the attribute `[SuppressDefaultHelpOption]` to disable the default --help behavior but that didn't seem to take.

My subcommand has the following options:

```
[Command(Name = "tools", OptionsComparison = StringComparison.InvariantCultureIgnoreCase, Description = "Run helpful developer tools and scripts")]
[SuppressDefaultHelpOption]
```

Can the default --help behavior be turned off for just a single subcommand so that I can do my own custom dynamic --help function?

Thanks!

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.