commandlineparser / commandlineparser/commandline
Why does using --help do this?
- Ngôn ngữ chính
- C#
- Star
- 4.8k
- Fork
- 478
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Tái hiện đầu ra trùng lặp với `--help` và so sánh với `--version`. Bắt đầu từ `Main`, sau đó lần theo `HelpText.AutoBuild` và `DefaultParsingErrorsHandler`, bao gồm cả callback được truyền vào `WithNotParsed`. Hoàn thành khi đã xác định được nguyên nhân của help bị trùng lặp, `--help` xuất ra một khối help duy nhất và `--version` vẫn không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp
- Lĩnh vực
- cli
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100