Skip to content

Commit

Permalink
(GH-54) Show help menu when unparsed options
Browse files Browse the repository at this point in the history
If there are any unparsed switches/options after parsing is considered
complete, then show the help menu. This is introduced to address a
minor regression introduced by
51d59c8
, where the help menu would no longer be shown if an option was not
parsed. It was previously handling this by throwing an error that would
cause the help menu to show up. However b/c of the way the bundled
option parsing is done, coupled with multiple passes through the
parser, some options may be misinterpreted as bundled options and throw
errors, which was corrected in the linked commit.

Add additional behavior to detect unparsed args and show the help menu
instead of attempting to roll with it.
  • Loading branch information
ferventcoder committed Feb 4, 2015
1 parent 52a47f2 commit 17e259a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/chocolatey/infrastructure.app/runners/ConsoleApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ public void run(string[] args, ChocolateyConfiguration config, Container contain
commandArgs,
config,
(optionSet) => command.configure_argument_parser(optionSet, config),
(unparsedArgs) => command.handle_additional_argument_parsing(unparsedArgs, config),
(unparsedArgs) => {
command.handle_additional_argument_parsing(unparsedArgs, config);

// all options / switches should be parsed,
// so show help menu if there are any left
foreach (var unparsedArg in unparsedArgs.or_empty_list_if_null())
{
if (unparsedArg.StartsWith("-") || unparsedArg.StartsWith("/"))
{
config.HelpRequested = true;
}
}
},
() => command.handle_validation(config),
() => command.help_message(config));
});
Expand Down

0 comments on commit 17e259a

Please sign in to comment.