commandlineparser / commandlineparser/commandline

Support for custom dynamic help option for a single subcommand?

Abierto
#704 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C#
Estrellas
4.8k
Forks
478
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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!

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.