commandlineparser / commandlineparser/commandline

Why does using --help do this?

Offen
#271 13 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
4.8k
Forks
478
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Reproduziere die doppelte Ausgabe mit `--help` und vergleiche sie mit `--version`. Beginne bei `Main` und verfolge dann `HelpText.AutoBuild` und `DefaultParsingErrorsHandler`, einschließlich des an `WithNotParsed` übergebenen Callbacks. Als erledigt gilt die Aufgabe, wenn die Ursache der doppelten Hilfe identifiziert ist, `--help` einen Help-Block ausgibt und `--version` unverändert bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.