Skip to content

Commit 8f2ac3c

Browse files
committed
also print out optional paramters (if any) when auto-printing help for missing parameters
1 parent 09a627d commit 8f2ac3c

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

GoCommando/Internals/CommandInvoker.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,39 @@ void InnerInvoke(IEnumerable<Switch> switches, EnvironmentSettings environmentSe
140140
&& !CanBeResolvedFromEnvironmentSettings(environmentSettings, p))
141141
.ToList();
142142

143+
var optionalParamtersNotSpecified = Parameters
144+
.Where(p => p.Optional
145+
&& !CanBeResolvedFromSwitches(switches, p)
146+
&& !CanBeResolvedFromEnvironmentSettings(environmentSettings, p))
147+
.ToList();
148+
143149
if (requiredParametersMissing.Any())
144150
{
145151
var requiredParametersMissingString = string.Join(Environment.NewLine,
146152
requiredParametersMissing.Select(p => $" {_settings.SwitchPrefix}{p.Name} - {p.DescriptionText}"));
147153

148-
throw new GoCommandoException(
149-
$@"The following required parameters are missing:
154+
var text = $@"The following required parameters are missing:
155+
156+
{requiredParametersMissingString}";
157+
158+
if (optionalParamtersNotSpecified.Any())
159+
{
160+
var optionalParamtersNotSpecifiedString = string.Join(Environment.NewLine,
161+
optionalParamtersNotSpecified.Select(p => $" {_settings.SwitchPrefix}{p.Name} - {p.DescriptionText}"));
162+
163+
var moreText = $@"The following optional parameters are also available:
164+
165+
{optionalParamtersNotSpecifiedString}";
166+
167+
throw new GoCommandoException(string.Concat(
168+
text,
169+
Environment.NewLine,
170+
Environment.NewLine,
171+
moreText
172+
));
173+
}
150174

151-
{requiredParametersMissingString}");
175+
throw new GoCommandoException(text);
152176
}
153177

154178
var switchesWithoutMathingParameter = switches

0 commit comments

Comments
 (0)