From 51d59c82e01a8ca0ad6bef918789a58fd2faf441 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 4 Feb 2015 01:02:41 -0600 Subject: [PATCH] (GH-54) Fix -version error 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. --- .../infrastructure/commandline/Options.cs | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/chocolatey/infrastructure/commandline/Options.cs b/src/chocolatey/infrastructure/commandline/Options.cs index 5591a6c25d..16fd848253 100644 --- a/src/chocolatey/infrastructure/commandline/Options.cs +++ b/src/chocolatey/infrastructure/commandline/Options.cs @@ -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; } @@ -860,6 +867,7 @@ private bool ParseBool (string option, string n, OptionContext c) private bool ParseBundledValue (string f, string n, OptionContext c) { + IDictionary normalOptions = new Dictionary(); if (f != "-") return false; for (int i = 0; i < n.Length; ++i) { @@ -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; }