commandlineparser / commandlineparser/commandline

Support for custom dynamic help option for a single subcommand?

Aperta
#704 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
4.8k
Fork
478
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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!

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.