question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why does using --help do this?

See original GitHub issue

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 "<path to error folder>"

  -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 "<path
                      to error folder>"

  -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<Options>(args);

            parserResult.WithParsed<Options>(options => OnSuccessfulParse(options));
            parserResult.WithNotParsed<Options>(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:

       /// <summary>
        /// Creates a new instance of the <see cref="CommandLine.Text.HelpText"/> class,
        /// automatically handling verbs or options scenario.
        /// </summary>
        /// <param name='parserResult'>The <see cref="CommandLine.ParserResult{T}"/> containing the instance that collected command line arguments parsed with <see cref="CommandLine.Parser"/> class.</param>
        /// <param name="maxDisplayWidth">The maximum width of the display.</param>
        /// <returns>
        /// An instance of <see cref="CommandLine.Text.HelpText"/> class.
        /// </returns>
        /// <remarks>This feature is meant to be invoked automatically by the parser, setting the HelpWriter property
        /// of <see cref="CommandLine.ParserSettings"/>.</remarks>
        public static HelpText AutoBuild<T>(ParserResult<T> parserResult, int maxDisplayWidth = DefaultMaximumLength)
        {
            if (parserResult.Tag != ParserResultType.NotParsed)
                throw new ArgumentException("Excepting NotParsed<T> type.", "parserResult");

            var errors = ((NotParsed<T>)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<HelpVerbRequestedError>().Single();
            var pr = new NotParsed<object>(TypeInfo.Create(err.Type), Enumerable.Empty<Error>());
            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?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Sirecommented, Jul 4, 2018

Nulling the HelpWriter works: var parserResult = new Parser(with => with.HelpWriter = null).ParseArguments<Options>(args); Instead of: var parserResult = CommandLine.Parser.Default.ParseArguments<Options>(args);

0reactions
ArthurAttoutcommented, Mar 24, 2021

Nulling the HelpWriter still shows a default help in my case :

public class Options
{
    [Value(0, MetaName = "instructions", HelpText = "Path to instructions file.")]
    public string InstructionsFilePath { get; set; }
}
var parser = new Parser(with => with.HelpWriter = null);
var parserResult = parser.ParseArguments<Options>(args);
Parser.Default.ParseArguments<Options>(args)
    .WithParsed(_start);

Calling myProgram.exe --help in a CLI returns :

MyProgram 1.0.0.0
Copyright ©  2021

  --help                   Display this help screen.

  --version                Display version information.

  instructions (pos. 0)    Path to instructions file.

While my understanding is that it should print nothing. Tested on 2.8.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

'Help do' vs. 'help to do' vs. 'help doing' in English
Both "help someone do something" and "help someone to do something" are acceptable. The form without "to" seems to be more common in...
Read more >
Help to do something or help do something?
It can be used as a full verb and as a modal verb. Today it is almost normal to use "to help" with...
Read more >
'it does help' why do you use 'do' in this sentence? Is it the ...
"it helps" is just stating the fact while "it does help" is emphasizing that it indeed helps. the emphasis might be in response...
Read more >
Help somebody (to) do - Grammar - Cambridge Dictionary
Help somebody (to) do ... We use help with or without an object: Let me help you. Can I help? We also use...
Read more >
What is the difference between “help do something” and “ ...
First phrase means to actually engage in the work to get something done: 'I helped her do the dishes.' Second phrase is to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found