Skip to content

Commit

Permalink
(GH-54) Fix -version error
Browse files Browse the repository at this point in the history
When option parsing attempts to parse -version, it sees it as a bundled
option because it finds -v as short option for verbose, so it errors on
-e, which isn't a short option. Instead it should not error and allow
the option to be picked up by possibly another set of option parsing.
  • Loading branch information
ferventcoder committed Feb 4, 2015
1 parent 8e2ad66 commit 51d59c8
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions src/chocolatey/infrastructure/commandline/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,16 @@ protected virtual bool Parse (string argument, OptionContext c)
if (ParseBool (argument, n, c))
return true;
// is it a bundled option?
if (ParseBundledValue (f, string.Concat (n + s + v), c))
return true;

try
{
if (ParseBundledValue(f, string.Concat(n + s + v), c))
return true;
}
catch (Exception ex)
{
"chocolatey".Log().Debug("Parsing {0} resulted in exception:{1} {2}".format_with(argument,Environment.NewLine,ex.Message));
}

return false;
}

Expand Down Expand Up @@ -860,6 +867,7 @@ private bool ParseBool (string option, string n, OptionContext c)

private bool ParseBundledValue (string f, string n, OptionContext c)
{
IDictionary<Option,string> normalOptions = new Dictionary<Option, string>();
if (f != "-")
return false;
for (int i = 0; i < n.Length; ++i) {
Expand All @@ -873,22 +881,32 @@ private bool ParseBundledValue (string f, string n, OptionContext c)
"Cannot bundle unregistered option '{0}'."), opt), opt);
}
p = this [rn];
switch (p.OptionValueType) {
case OptionValueType.None:
Invoke (c, opt, n, p);
break;
case OptionValueType.Optional:
case OptionValueType.Required: {
string v = n.Substring (i+1);
c.Option = p;
c.OptionName = opt;
ParseValue (v.Length != 0 ? v : null, c);
return true;
}
default:
throw new InvalidOperationException ("Unknown OptionValueType: " + p.OptionValueType);
}

switch (p.OptionValueType)
{
case OptionValueType.None:
normalOptions.Add(p, opt);
break;
case OptionValueType.Optional:
case OptionValueType.Required:
{
string v = n.Substring(i + 1);
c.Option = p;
c.OptionName = opt;
ParseValue(v.Length != 0 ? v : null, c);
return true;
}
default:
throw new InvalidOperationException("Unknown OptionValueType: " + p.OptionValueType);
}
}

// only invoke options for bundled if all options exist
foreach (var option in normalOptions)
{
Invoke(c, option.Value, n, option.Key);
}

return true;
}

Expand Down

0 comments on commit 51d59c8

Please sign in to comment.