commandlineparser / commandlineparser/commandline

Support for custom dynamic help option for a single subcommand?

オープン
#704 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C#
スター
4.8k
フォーク
478
PR マージ指標
30日以内にマージされた PR はありません

説明

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!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。