Example #1
0
        public string MergeTemplates(VersionParts incoming, VersionParts existing)
        {
            string result = "";

            for (int i = 0; i < 4; i++)
            {
                //SafeLog("StampAssemblies: incoming[{0}]={1}", i, incoming.parts[i]);
                //SafeLog("StampAssemblies: existing[{0}]={1}", i, existing.parts[i]);
                if (incoming.parts[i] != "*")
                {
                    result += incoming.parts[i] + ".";
                }
                else
                {
                    if (existing.parts[i] == "*")
                    {
                        //SafeLog("StampAssemblies: existing.parts[i] == '*'");
                        result += "0.";
                    }
                    else
                    {
                        result += existing.parts[i] + ".";
                    }
                }
            }
            return(result.TrimEnd(new char[] { '.' }));
        }
Example #2
0
        private string ExpandTemplate(string regexTemplate, string replaceTemplate, string whichVersion,
                                      string contents, VersionParts incomingVersion, VersionFormat format = VersionFormat.File)
        {
            try
            {
                var regex  = new Regex(string.Format(regexTemplate, whichVersion));
                var result = regex.Match(contents);
                if (result == Match.Empty)
                {
                    return(contents);
                }
                var versionTemplateInFile = ParseVersionString(result.Groups[1].Value, format);
                var newVersion            = MergeTemplates(incomingVersion, versionTemplateInFile);

                SafeLog("StampAssemblies: Merging existing {0} with incoming {1} to produce {2}.",
                        versionTemplateInFile.ToString(), incomingVersion.ToString(), newVersion);
                return(regex.Replace(contents, string.Format(replaceTemplate, whichVersion, newVersion)));
            }
            catch (Exception e)
            {
                Log.LogError("Could not parse the {0} attribute, which should be something like 0.7.*.* or 1.0.0.0",
                             whichVersion);
                Log.LogErrorFromException(e);
                throw;
            }
        }
Example #3
0
        public string GetModifiedContents(string contents, string incomingVersion, string incomingFileVersion)
        {
            var          versionTemplateInFile        = GetExistingAssemblyVersion(contents);
            var          fileVersionTemplateInFile    = GetExistingAssemblyFileVersion(contents);
            var          versionTemplateInBuildScript = ParseVersionString(incomingVersion);
            VersionParts fileVersionTemplateInScript  = null;

            fileVersionTemplateInScript = incomingFileVersion != null?ParseVersionString(incomingFileVersion)
                                              : versionTemplateInBuildScript;

            var newVersion     = MergeTemplates(versionTemplateInBuildScript, versionTemplateInFile);
            var newFileVersion = MergeTemplates(fileVersionTemplateInScript, fileVersionTemplateInFile);

            SafeLog("StampAssemblies: Merging existing {0} with incoming {1} to produce {2}.",
                    versionTemplateInFile.ToString(), incomingVersion, newVersion);
            SafeLog("StampAssemblies: Merging existing {0} with incoming {1} to produce {2}.",
                    fileVersionTemplateInFile.ToString(), incomingFileVersion, newFileVersion);


            var replacement = string.Format(
                "[assembly: AssemblyVersion(\"{0}\")]",
                newVersion);

            contents    = Regex.Replace(contents, @"\[assembly: AssemblyVersion\("".*""\)\]", replacement);
            replacement = string.Format(
                "[assembly: AssemblyFileVersion(\"{0}\")]",
                newFileVersion);
            contents = Regex.Replace(contents, @"\[assembly: AssemblyFileVersion\("".*""\)\]", replacement);
            return(contents);
        }
Example #4
0
        private string ModifyCodeAttributes(string contents, VersionParts version, VersionParts fileVersion,
                                            VersionParts infoVersion)
        {
            const string regexTemplate   = @"\[assembly\: {0}\(""(.+)""";
            const string replaceTemplate = @"[assembly: {0}(""{1}""";

            contents = ExpandTemplate(regexTemplate, replaceTemplate, "AssemblyVersion", contents, version);
            contents = ExpandTemplate(regexTemplate, replaceTemplate, "AssemblyFileVersion", contents, fileVersion);
            contents = ExpandTemplate(regexTemplate, replaceTemplate, "AssemblyInformationalVersion", contents,
                                      infoVersion, VersionFormat.Info);
            return(contents);
        }
Example #5
0
        private string ModifyMSBuildProps(string contents, VersionParts version, VersionParts fileVersion,
                                          VersionParts infoVersion, VersionParts packageVersion)
        {
            const string regexTemplate   = "<{0}>(.+)</{0}>";
            const string replaceTemplate = "<{0}>{1}</{0}>";

            contents = ExpandTemplate(regexTemplate, replaceTemplate, "AssemblyVersion", contents, version);
            contents = ExpandTemplate(regexTemplate, replaceTemplate, "FileVersion", contents, fileVersion);
            contents = ExpandTemplate(regexTemplate, replaceTemplate, "InformationalVersion", contents, infoVersion,
                                      VersionFormat.Info);
            contents = ExpandTemplate(regexTemplate, replaceTemplate, "Version", contents, packageVersion,
                                      VersionFormat.Semantic);

            return(contents);
        }
Example #6
0
        internal string GetModifiedContents(string contents, bool isCode, string versionStr, string fileVersionStr,
                                            string packageVersionStr)
        {
            // ENHANCE: add property for InformationalVersion
            VersionParts version     = ParseVersionString(versionStr);
            VersionParts fileVersion = fileVersionStr != null?ParseVersionString(fileVersionStr) : version;

            VersionParts infoVersion    = ParseVersionString(versionStr, VersionFormat.Info);
            VersionParts packageVersion = packageVersionStr != null
                                ? ParseVersionString(packageVersionStr, VersionFormat.Semantic)
                                : version;

            if (isCode)
            {
                return(ModifyCodeAttributes(contents, version, fileVersion, infoVersion));
            }
            return(ModifyMSBuildProps(contents, version, fileVersion, infoVersion, packageVersion));
        }
Example #7
0
        public string MergeTemplates(VersionParts incoming, VersionParts existing)
        {
            VersionParts result = new VersionParts
            {
                parts      = (string[])existing.parts.Clone(),
                Prerelease = incoming.Prerelease ?? existing.Prerelease
            };

            for (int i = 0; i < result.parts.Length; i++)
            {
                if (incoming.parts[i] != "*")
                {
                    result.parts[i] = incoming.parts[i];
                }
                else if (existing.parts[i] == "*")
                {
                    result.parts[i] = "0";
                }
            }
            return(result.ToString());
        }
Example #8
0
        public VersionParts ParseVersionString(string contents)
        {
            var result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)\.(.+)");

            if (!result.Success)
            {
                //handle 1.0.*  (I'm not good enough with regex to
                //overcome greediness and get a single pattern to work for both situations).
                result = Regex.Match(contents, @"(.+)\.(.+)\.(\*)");
            }
            if (!result.Success)
            {
                //handle 0.0.12
                result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)");
            }
            var v = new VersionParts();

            v.parts[0] = result.Groups[1].Value;
            v.parts[1] = result.Groups[2].Value;
            v.parts[2] = result.Groups[3].Value;
            v.parts[3] = result.Groups[4].Value;

            for (int i = 0; i < 4; i++)
            {
                if (string.IsNullOrEmpty(v.parts[i]))
                {
                    v.parts[i] = "*";
                }
            }
            //can't propogate a hash code, though it's nice (for build server display purposes)
            //to send it through to us. So for now, we just strip it out.
            if (v.parts[3].IndexOfAny(new char[] { 'a', 'b', 'c', 'd', 'e', 'f' }) > -1)
            {
                v.parts[3] = "0";
            }

            return(v);
        }
Example #9
0
        public VersionParts ParseVersionString(string contents, bool allowHashAsRevision = false)
        {
            var result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)\.(.+)");

            if (!result.Success)
            {
                //handle 1.0.*  (I'm not good enough with regex to
                //overcome greediness and get a single pattern to work for both situations).
                result = Regex.Match(contents, @"(.+)\.(.+)\.(\*)");
            }
            if (!result.Success)
            {
                //handle 0.0.12
                result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)");
            }
            var v = new VersionParts();

            v.parts[0] = result.Groups[1].Value;
            v.parts[1] = result.Groups[2].Value;
            v.parts[2] = result.Groups[3].Value;
            v.parts[3] = result.Groups[4].Value;

            for (int i = 0; i < 4; i++)
            {
                if (string.IsNullOrEmpty(v.parts[i]))
                {
                    v.parts[i] = "*";
                }
            }

            if (!allowHashAsRevision && v.parts[3].IndexOfAny(new char[] { 'a', 'b', 'c', 'd', 'e', 'f' }) > -1)
            {
                // zero out hash code which we can't have in numeric version numbers
                v.parts[3] = "0";
            }

            return(v);
        }
Example #10
0
		private string ExpandTemplate(string whichAttribute, string contents,
			VersionParts incomingVersion, bool allowHashAsRevision)
		{
			try
			{
				var regex = new Regex(string.Format(@"\[assembly\: {0}\(""(.+)""", whichAttribute));
				var result = regex.Match(contents);
				if (result == Match.Empty)
					return contents;
				var versionTemplateInFile = ParseVersionString(result.Groups[1].Value, allowHashAsRevision);
				var newVersion = MergeTemplates(incomingVersion, versionTemplateInFile);

				SafeLog("StampAssemblies: Merging existing {0} with incoming {1} to produce {2}.",
					versionTemplateInFile.ToString(), incomingVersion.ToString(), newVersion);
				return regex.Replace(contents, string.Format(@"[assembly: {0}(""{1}""", whichAttribute, newVersion));
			}
			catch (Exception e)
			{
				Log.LogError("Could not parse the {0} attribute, which should be something like 0.7.*.* or 1.0.0.0",
					whichAttribute);
				Log.LogErrorFromException(e);
				throw e;
			}
		}
 public string MergeTemplates(VersionParts incoming, VersionParts existing)
 {
     string result = "";
     for (int i = 0; i < 4; i++)
     {
         //SafeLog("StampAssemblies: incoming[{0}]={1}", i, incoming.parts[i]);
         //SafeLog("StampAssemblies: existing[{0}]={1}", i, existing.parts[i]);
         if(incoming.parts[i] != "*")
         {
             result += incoming.parts[i] + ".";
         }
         else
         {
             if(existing.parts[i] == "*")
             {
                 //SafeLog("StampAssemblies: existing.parts[i] == '*'");
                 result += "0.";
             }
             else
             {
                 result += existing.parts[i] + ".";
             }
         }
     }
     return result.TrimEnd(new char[] {'.'});
 }
Example #12
0
        private static VersionParts ParseVersionString(string contents, VersionFormat format)
        {
            VersionParts v;

            if (format == VersionFormat.Semantic)
            {
                Match result = Regex.Match(contents, @"([\d\*]+)\.([\d\*]+)\.([\d\*]+)(?:\-(.*))?");

                v = new VersionParts
                {
                    parts = new[]
                    {
                        result.Groups[1].Value,
                        result.Groups[2].Value,
                        result.Groups[3].Value
                    },
                    Prerelease = result.Groups[4].Value
                };
            }
            else
            {
                Match result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)\.(.+)");
                if (!result.Success)
                {
                    //handle 1.0.*  (I'm not good enough with regex to
                    //overcome greediness and get a single pattern to work for both situations).
                    result = Regex.Match(contents, @"(.+)\.(.+)\.(\*)");
                }
                if (!result.Success)
                {
                    //handle 0.0.12
                    result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)");
                }

                v = new VersionParts
                {
                    parts = new[]
                    {
                        result.Groups[1].Value,
                        result.Groups[2].Value,
                        result.Groups[3].Value,
                        result.Groups[4].Value
                    }
                };

                if (format == VersionFormat.File && v.parts.Length == 4 &&
                    v.parts[3].IndexOfAny(new[] { 'a', 'b', 'c', 'd', 'e', 'f' }) != -1)
                {
                    // zero out hash code which we can't have in numeric version numbers
                    v.parts[3] = "0";
                }
            }

            for (int i = 0; i < v.parts.Length; i++)
            {
                if (string.IsNullOrEmpty(v.parts[i]))
                {
                    v.parts[i] = "*";
                }
            }

            return(v);
        }
Example #13
0
        public static Arguments ParseArguments(List <string> commandLineArguments)
        {
            if (commandLineArguments.Count == 0)
            {
                return(new Arguments
                {
                    TargetPath = Environment.CurrentDirectory
                });
            }

            var firstArgument = commandLineArguments.First();

            if (IsHelp(firstArgument))
            {
                return(new Arguments
                {
                    IsHelp = true
                });
            }
            if (IsInit(firstArgument))
            {
                return(new Arguments
                {
                    TargetPath = Environment.CurrentDirectory,
                    Init = true
                });
            }

            if (commandLineArguments.Count == 1 && !(commandLineArguments[0].StartsWith("-") || commandLineArguments[0].StartsWith("/")))
            {
                return(new Arguments
                {
                    TargetPath = firstArgument
                });
            }

            List <string> namedArguments;
            var           arguments = new Arguments();

            if (firstArgument.StartsWith("-") || firstArgument.StartsWith("/"))
            {
                arguments.TargetPath = Environment.CurrentDirectory;
                namedArguments       = commandLineArguments;
            }
            else
            {
                arguments.TargetPath = firstArgument;
                namedArguments       = commandLineArguments.Skip(1).ToList();
            }

            var args = CollectSwitchesAndValuesFromArguments(namedArguments);

            foreach (var name in args.AllKeys)
            {
                var values = args.GetValues(name);

                string value = null;

                if (values != null)
                {
                    //Currently, no arguments use more than one value, so having multiple values is an input error.
                    //In the future, this exception can be removed to support multiple values for a switch.
                    if (values.Length > 1)
                    {
                        throw new WarningException(string.Format("Could not parse command line parameter '{0}'.", values[1]));
                    }

                    value = values.FirstOrDefault();
                }

                if (IsSwitch("l", name))
                {
                    arguments.LogFilePath = value;
                    continue;
                }

                if (IsSwitch("targetpath", name))
                {
                    arguments.TargetPath = value;
                    continue;
                }

                if (IsSwitch("dynamicRepoLocation", name))
                {
                    arguments.DynamicRepositoryLocation = value;
                    continue;
                }

                if (IsSwitch("url", name))
                {
                    arguments.TargetUrl = value;
                    continue;
                }

                if (IsSwitch("b", name))
                {
                    arguments.TargetBranch = value;
                    continue;
                }

                if (IsSwitch("u", name))
                {
                    arguments.Authentication.Username = value;
                    continue;
                }

                if (IsSwitch("p", name))
                {
                    arguments.Authentication.Password = value;
                    continue;
                }

                if (IsSwitch("c", name))
                {
                    arguments.CommitId = value;
                    continue;
                }

                if (IsSwitch("exec", name))
                {
                    arguments.Exec = value;
                    continue;
                }

                if (IsSwitch("execargs", name))
                {
                    arguments.ExecArgs = value;
                    continue;
                }

                if (IsSwitch("proj", name))
                {
                    arguments.Proj = value;
                    continue;
                }

                if (IsSwitch("projargs", name))
                {
                    arguments.ProjArgs = value;
                    continue;
                }

                if (IsSwitch("updateAssemblyInfo", name))
                {
                    if (new[] { "1", "true" }.Contains(value))
                    {
                        arguments.UpdateAssemblyInfo = true;
                    }
                    else if (new[] { "0", "false" }.Contains(value))
                    {
                        arguments.UpdateAssemblyInfo = false;
                    }
                    else if (!IsSwitchArgument(value))
                    {
                        arguments.UpdateAssemblyInfo         = true;
                        arguments.UpdateAssemblyInfoFileName = value;
                    }
                    else
                    {
                        arguments.UpdateAssemblyInfo = true;
                    }
                    continue;
                }

                if (IsSwitch("assemblyversionformat", name))
                {
                    throw new WarningException("assemblyversionformat switch removed, use AssemblyVersioningScheme configuration value instead");
                }

                if ((IsSwitch("v", name)) && VersionParts.Contains(value.ToLower()))
                {
                    arguments.ShowVariable = value.ToLower();
                    continue;
                }

                if (IsSwitch("showConfig", name))
                {
                    if (new[] { "1", "true" }.Contains(value))
                    {
                        arguments.ShowConfig = true;
                    }
                    else if (new[] { "0", "false" }.Contains(value))
                    {
                        arguments.UpdateAssemblyInfo = false;
                    }
                    else
                    {
                        arguments.ShowConfig = true;
                    }
                    continue;
                }

                if (IsSwitch("output", name))
                {
                    OutputType outputType;
                    if (!Enum.TryParse(value, true, out outputType))
                    {
                        throw new WarningException(string.Format("Value '{0}' cannot be parsed as output type, please use 'json' or 'buildserver'", value));
                    }

                    arguments.Output = outputType;
                    continue;
                }

                if (IsSwitch("nofetch", name))
                {
                    arguments.NoFetch = true;
                    continue;
                }

                throw new WarningException(string.Format("Could not parse command line parameter '{0}'.", name));
            }

            return(arguments);
        }
Example #14
0
		public VersionParts ParseVersionString(string contents, bool allowHashAsRevision = false)
		{
			var result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)\.(.+)");
			if(!result.Success)
			{
				//handle 1.0.*  (I'm not good enough with regex to
				//overcome greediness and get a single pattern to work for both situations).
				result = Regex.Match(contents, @"(.+)\.(.+)\.(\*)");
			}
			if (!result.Success)
			{
				//handle 0.0.12
				result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)");
			}
			var v = new VersionParts();
			v.parts[0] = result.Groups[1].Value;
			v.parts[1] = result.Groups[2].Value;
			v.parts[2] = result.Groups[3].Value;
			v.parts[3] = result.Groups[4].Value;

			for (int i = 0; i < 4; i++)
			{
				if(string.IsNullOrEmpty(v.parts[i]))
				{
					v.parts[i] = "*";
				}
			}

			if(!allowHashAsRevision && v.parts[3].IndexOfAny(new char[]{'a','b','c','d','e','f'}) >-1)
			{
				// zero out hash code which we can't have in numeric version numbers
				v.parts[3] = "0";
			}

			return v;
		}
        public VersionParts ParseVersionString(string contents)
        {
            var result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)\.(.+)");
            if(!result.Success)
            {
                //handle 1.0.*  (I'm not good enough with regex to
                //overcome greediness and get a single pattern to work for both situations).
                result = Regex.Match(contents, @"(.+)\.(.+)\.(\*)");
            }
            if (!result.Success)
            {
                //handle 0.0.12
                result = Regex.Match(contents, @"(.+)\.(.+)\.(.+)");
            }
            var v = new VersionParts();
            v.parts[0] = result.Groups[1].Value;
            v.parts[1] = result.Groups[2].Value;
            v.parts[2] = result.Groups[3].Value;
            v.parts[3] = result.Groups[4].Value;

            for (int i = 0; i < 4; i++)
            {
                if(string.IsNullOrEmpty(v.parts[i]))
                {
                    v.parts[i] = "*";
                }
            }
            //can't propogate a hash code, though it's nice (for build server display purposes)
            //to send it through to us. So for now, we just strip it out.
            if(v.parts[3].IndexOfAny(new char[]{'a','b','c','d','e','f'}) >-1)
            {
                v.parts[3] = "0";
            }

            return v;
        }
Example #16
0
        public static Arguments ParseArguments(List <string> commandLineArguments)
        {
            if (commandLineArguments.Count == 0)
            {
                return(new Arguments
                {
                    TargetPath = Environment.CurrentDirectory
                });
            }

            var firstArgument = commandLineArguments.First();

            if (IsHelp(firstArgument))
            {
                return(new Arguments
                {
                    IsHelp = true
                });
            }
            if (IsInit(firstArgument))
            {
                return(new Arguments
                {
                    TargetPath = Environment.CurrentDirectory,
                    Init = true
                });
            }

            if (commandLineArguments.Count == 1 && !(commandLineArguments[0].StartsWith("-") || commandLineArguments[0].StartsWith("/")))
            {
                return(new Arguments
                {
                    TargetPath = firstArgument
                });
            }

            List <string> namedArguments;
            var           arguments = new Arguments();

            if (firstArgument.StartsWith("-") || firstArgument.StartsWith("/"))
            {
                arguments.TargetPath = Environment.CurrentDirectory;
                namedArguments       = commandLineArguments;
            }
            else
            {
                arguments.TargetPath = firstArgument;
                namedArguments       = commandLineArguments.Skip(1).ToList();
            }

            for (var index = 0; index < namedArguments.Count; index = index + 2)
            {
                var name  = namedArguments[index];
                var value = namedArguments.Count > index + 1 ? namedArguments[index + 1] : null;

                if (IsSwitch("l", name))
                {
                    arguments.LogFilePath = value;
                    continue;
                }

                if (IsSwitch("targetpath", name))
                {
                    arguments.TargetPath = value;
                    continue;
                }

                if (IsSwitch("url", name))
                {
                    arguments.TargetUrl = value;
                    continue;
                }

                if (IsSwitch("b", name))
                {
                    arguments.TargetBranch = value;
                    continue;
                }

                if (IsSwitch("u", name))
                {
                    arguments.Authentication.Username = value;
                    continue;
                }

                if (IsSwitch("p", name))
                {
                    arguments.Authentication.Password = value;
                    continue;
                }

                if (IsSwitch("c", name))
                {
                    arguments.CommitId = value;
                    continue;
                }

                if (IsSwitch("exec", name))
                {
                    arguments.Exec = value;
                    continue;
                }

                if (IsSwitch("execargs", name))
                {
                    arguments.ExecArgs = value;
                    continue;
                }

                if (IsSwitch("proj", name))
                {
                    arguments.Proj = value;
                    continue;
                }

                if (IsSwitch("projargs", name))
                {
                    arguments.ProjArgs = value;
                    continue;
                }

                if (IsSwitch("updateAssemblyInfo", name))
                {
                    if (new[] { "1", "true" }.Contains(value))
                    {
                        arguments.UpdateAssemblyInfo = true;
                    }
                    else if (new[] { "0", "false" }.Contains(value))
                    {
                        arguments.UpdateAssemblyInfo = false;
                    }
                    else if (!IsSwitchArgument(value))
                    {
                        arguments.UpdateAssemblyInfo         = true;
                        arguments.UpdateAssemblyInfoFileName = value;
                    }
                    else
                    {
                        arguments.UpdateAssemblyInfo = true;
                        index--;
                    }
                    continue;
                }

                if (IsSwitch("assemblyversionformat", name))
                {
                    throw new WarningException("assemblyversionformat switch removed, use AssemblyVersioningScheme configuration value instead");
                }

                if ((IsSwitch("v", name)) && VersionParts.Contains(value.ToLower()))
                {
                    arguments.ShowVariable = value.ToLower();
                    continue;
                }

                if (IsSwitch("showConfig", name))
                {
                    if (new[] { "1", "true" }.Contains(value))
                    {
                        arguments.ShowConfig = true;
                    }
                    else if (new[] { "0", "false" }.Contains(value))
                    {
                        arguments.UpdateAssemblyInfo = false;
                    }
                    else
                    {
                        arguments.ShowConfig = true;
                        index--;
                    }
                    continue;
                }

                if (IsSwitch("output", name))
                {
                    OutputType outputType;
                    if (!Enum.TryParse(value, true, out outputType))
                    {
                        throw new WarningException(string.Format("Value '{0}' cannot be parsed as output type, please use 'json' or 'buildserver'", value));
                    }

                    arguments.Output = outputType;
                    continue;
                }

                throw new WarningException(string.Format("Could not parse command line parameter '{0}'.", name));
            }

            return(arguments);
        }
Example #17
0
        public static Arguments ParseArguments(List <string> commandLineArguments)
        {
            if (commandLineArguments.Count == 0)
            {
                return(new Arguments
                {
                    TargetPath = Environment.CurrentDirectory
                });
            }

            var firstArgument = commandLineArguments.First();

            if (IsHelp(firstArgument))
            {
                return(new Arguments
                {
                    IsHelp = true
                });
            }

            if (commandLineArguments.Count == 1)
            {
                return(new Arguments
                {
                    TargetPath = firstArgument
                });
            }

            List <string> namedArguments;
            var           arguments = new Arguments();

            if (firstArgument.StartsWith("-") || firstArgument.StartsWith("/"))
            {
                arguments.TargetPath = Environment.CurrentDirectory;
                namedArguments       = commandLineArguments;
            }
            else
            {
                arguments.TargetPath = firstArgument;
                namedArguments       = commandLineArguments.Skip(1).ToList();
            }

            EnsureArgumentsEvenCount(commandLineArguments, namedArguments);

            for (var index = 0; index < namedArguments.Count; index = index + 2)
            {
                var name  = namedArguments[index];
                var value = namedArguments[index + 1];

                if (IsSwitch("l", name))
                {
                    arguments.LogFilePath = value;
                    continue;
                }

                if (IsSwitch("url", name))
                {
                    arguments.TargetUrl = value;
                    continue;
                }

                if (IsSwitch("b", name))
                {
                    arguments.TargetBranch = value;
                    continue;
                }

                if (IsSwitch("u", name))
                {
                    arguments.Username = value;
                    continue;
                }

                if (IsSwitch("p", name))
                {
                    arguments.Password = value;
                    continue;
                }

                if ((IsSwitch("v", name)) && VersionParts.Contains(value.ToLower()))
                {
                    arguments.VersionPart = value.ToLower();
                    continue;
                }

                if (IsSwitch("output", name))
                {
                    var outputType = OutputType.Json;
                    if (!Enum.TryParse(value, true, out outputType))
                    {
                        throw new ErrorException(string.Format("Value '{0}' cannot be parsed as output type, please use 'json' or 'buildserver'", value));
                    }

                    arguments.Output = outputType;
                    continue;
                }

                throw new ErrorException(string.Format("Could not parse command line parameter '{0}'.", name));
            }
            return(arguments);
        }