Skip to content

Commit

Permalink
also print out optional paramters (if any) when auto-printing help fo…
Browse files Browse the repository at this point in the history
…r missing parameters
  • Loading branch information
mookid8000 committed Apr 27, 2017
1 parent 09a627d commit 8f2ac3c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions GoCommando/Internals/CommandInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,39 @@ void InnerInvoke(IEnumerable<Switch> switches, EnvironmentSettings environmentSe
&& !CanBeResolvedFromEnvironmentSettings(environmentSettings, p))
.ToList();

var optionalParamtersNotSpecified = Parameters
.Where(p => p.Optional
&& !CanBeResolvedFromSwitches(switches, p)
&& !CanBeResolvedFromEnvironmentSettings(environmentSettings, p))
.ToList();

if (requiredParametersMissing.Any())
{
var requiredParametersMissingString = string.Join(Environment.NewLine,
requiredParametersMissing.Select(p => $" {_settings.SwitchPrefix}{p.Name} - {p.DescriptionText}"));

throw new GoCommandoException(
$@"The following required parameters are missing:
var text = $@"The following required parameters are missing:
{requiredParametersMissingString}";

if (optionalParamtersNotSpecified.Any())
{
var optionalParamtersNotSpecifiedString = string.Join(Environment.NewLine,
optionalParamtersNotSpecified.Select(p => $" {_settings.SwitchPrefix}{p.Name} - {p.DescriptionText}"));

var moreText = $@"The following optional parameters are also available:
{optionalParamtersNotSpecifiedString}";

throw new GoCommandoException(string.Concat(
text,
Environment.NewLine,
Environment.NewLine,
moreText
));
}

{requiredParametersMissingString}");
throw new GoCommandoException(text);
}

var switchesWithoutMathingParameter = switches
Expand Down

0 comments on commit 8f2ac3c

Please sign in to comment.