commandlineparser / commandlineparser/commandline

Why does using --help do this?

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

説明

Out of interest now when I use `--help` I get the help listed twice:
```
C:\Program Files (x86)\Meeting Schedule Assistant\OutlookCalIFConsole>outlookcalifconsole --help
OutlookCalIFConsole 2018.4.4.1
Copyright c 2017 - 2018

-l, --list Builds a list of available calendars. Eg: -l ".\CalendarList.xml"

-m, --mode Type of events to add to the calendar. Modes: mwb. Eg: -m mwb

-p, --path Path to the events data file. Eg: -p ".\EventsToAdd.xml"

-t, --tokencache Required. The location of the token cache data file. Eg: -t "file.dat"

-e, --errorlog Required. The location for the error log. Eg: -e ""

-s, --signout Sign out from Outlook calendar

--help Display this help screen.

--version Display version information.

OutlookCalIFConsole 2018.4.4.1
Copyright c 2017 - 2018

-l, --list Builds a list of available calendars. Eg: -l
".\CalendarList.xml"

-m, --mode Type of events to add to the calendar. Modes: mwb. Eg: -m
mwb

-p, --path Path to the events data file. Eg: -p ".\EventsToAdd.xml"

-t, --tokencache Required. The location of the token cache data file. Eg:
-t "file.dat"

-e, --errorlog Required. The location for the error log. Eg: -e ""

-s, --signout Sign out from Outlook calendar

--help Display this help screen.

--version Display version information.
```
Why might this be? If I use `--version` it is not listed twice.

I am using standard code to build the help:

```
static int Main(string[] args)
{
var parserResult = CommandLine.Parser.Default.ParseArguments(args);

parserResult.WithParsed(options => OnSuccessfulParse(options));
parserResult.WithNotParsed(errs =>
{
var helpText = HelpText.AutoBuild(parserResult, h =>
{
return HelpText.DefaultParsingErrorsHandler(parserResult, h);
}, e =>
{
return e;
});
Console.WriteLine(helpText);
ReturnErrorCode = ErrorCode.CommandLineArguments;
});

return (int)ReturnErrorCode;
}
```

Also, why doesn't the default `help `keyword have a short version of `h`?

Looking here:

```
///
/// Creates a new instance of the class,
/// automatically handling verbs or options scenario.
///
/// The containing the instance that collected command line arguments parsed with class.
/// The maximum width of the display.
///
/// An instance of class.
///
/// This feature is meant to be invoked automatically by the parser, setting the HelpWriter property
/// of .
public static HelpText AutoBuild(ParserResult parserResult, int maxDisplayWidth = DefaultMaximumLength)
{
if (parserResult.Tag != ParserResultType.NotParsed)
throw new ArgumentException("Excepting NotParsed type.", "parserResult");

var errors = ((NotParsed)parserResult).Errors;

if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError))
return new HelpText(HeadingInfo.Default){MaximumDisplayWidth = maxDisplayWidth }.AddPreOptionsLine(Environment.NewLine);

if (!errors.Any(e => e.Tag == ErrorType.HelpVerbRequestedError))
return AutoBuild(parserResult, current => DefaultParsingErrorsHandler(parserResult, current), e => e, maxDisplayWidth: maxDisplayWidth);

var err = errors.OfType().Single();
var pr = new NotParsed(TypeInfo.Create(err.Type), Enumerable.Empty());
return err.Matched
? AutoBuild(pr, current => DefaultParsingErrorsHandler(pr, current), e => e, maxDisplayWidth: maxDisplayWidth)
: AutoBuild(parserResult, current => DefaultParsingErrorsHandler(parserResult, current), e => e, true, maxDisplayWidth);
}
```
It seems to me that it itself calls `DefaultParsingErrorsHandler`. Yet in my code it looks like we do it again. Is this a mistake in my code or something?

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

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

調査の方向性

`--help` で重複する出力を再現し、`--version` と比較します。`Main` から開始し、`WithNotParsed` に渡される callback を含めて、`HelpText.AutoBuild` と `DefaultParsingErrorsHandler` を追跡します。`--help` が 1 つの help ブロックを出力し、`--version` が変更されないままになる状態で、重複した help の原因を特定できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp
領域
cli
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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