diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index a0c7c544aa..1e89ddacc6 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -193,10 +193,7 @@ public void Unknown_argument_should_throw() } [TestCase("-updateAssemblyInfo")] - [TestCase("-updateAssemblyInfo+")] // plus added to flag indicates true [TestCase("-updateAssemblyInfo -proj foo.sln")] - [TestCase("-updateAssemblyInfo true")] // bogus test: flags should not be implemented this way, breaking change - [TestCase("-updateAssemblyInfo 1")] // bogus test: flags should not be implemented this way, breaking change public void update_assembly_info_true(string command) { var arguments = ArgumentParser.ParseArguments(command); @@ -204,28 +201,27 @@ public void update_assembly_info_true(string command) } [TestCase("-proj foo.sln")] // absent updateAssemblyInfo flag implies false - [TestCase("-updateAssemblyInfo-")] // minus switch added to flag indicates explicit false value for flag - [TestCase("-updateAssemblyInfo false")] // bogus test: flags should not be implemented this way, breaking change - [TestCase("-updateAssemblyInfo 0")] // bogus test: flags should not be implemented this way, breaking change + [TestCase("")] public void update_assembly_info_false(string command) { var arguments = ArgumentParser.ParseArguments(command); arguments.UpdateAssemblyInfo.ShouldBe(false); } - // how to do switch-and-value options? - [Test] - public void update_assembly_info_with_filename() + [TestCase("-updateAssemblyInfo=CommonAssemblyInfo.cs")] + [TestCase("-updateAssemblyInfo:CommonAssemblyInfo.cs")] + public void update_assembly_info_with_filename(string args) { - var arguments = ArgumentParser.ParseArguments("-updateAssemblyInfo CommonAssemblyInfo.cs"); + var arguments = ArgumentParser.ParseArguments(args); arguments.UpdateAssemblyInfo.ShouldBe(true); arguments.UpdateAssemblyInfoFileName.ShouldBe("CommonAssemblyInfo.cs"); } - [Test] - public void update_assembly_info_with_relative_filename() + [TestCase("-updateAssemblyInfo=..\\..\\CommonAssemblyInfo.cs")] + [TestCase("-updateAssemblyInfo:..\\..\\CommonAssemblyInfo.cs")] + public void update_assembly_info_with_relative_filename(string args) { - var arguments = ArgumentParser.ParseArguments("-updateAssemblyInfo ..\\..\\CommonAssemblyInfo.cs"); + var arguments = ArgumentParser.ParseArguments(args); arguments.UpdateAssemblyInfo.ShouldBe(true); arguments.UpdateAssemblyInfoFileName.ShouldBe("..\\..\\CommonAssemblyInfo.cs"); } diff --git a/src/GitVersionExe/ArgumentParser.cs b/src/GitVersionExe/ArgumentParser.cs index 0d5afb8b91..4f31c34c0a 100644 --- a/src/GitVersionExe/ArgumentParser.cs +++ b/src/GitVersionExe/ArgumentParser.cs @@ -63,9 +63,20 @@ public static OptionSet GetOptionSet(Arguments arguments) v => arguments.TargetBranch = v }, { - "updateassemblyinfo", "Will recursively search for all 'AssemblyInfo.cs' files in the git repo and update them", - v => arguments.UpdateAssemblyInfo = (v != null) - }, // we should be able to use : as optional value here; then == null will indicate it was specified without value + "updateassemblyinfo:", "Will recursively search for all 'AssemblyInfo.cs' files in the git repo and update them", + v => + { + if (v == null) + { + arguments.UpdateAssemblyInfo = true; + } + else + { + arguments.UpdateAssemblyInfo = true; + arguments.UpdateAssemblyInfoFileName = v; + } + } + }, // we should be able to use : as optional value here; then == null will indicate it was specified without value { "dynamicrepolocation=", "By default dynamic repositories will be cloned to %tmp%. Use this switch to override", v => arguments.DynamicRepositoryLocation = v @@ -197,21 +208,6 @@ static bool IsSwitchArgument(string value) && !Regex.Match(value, @"/\w+:").Success; //Exclude msbuild & project parameters in form /blah:, which should be parsed as values, not switch names. } - static bool IsSwitch(string switchName, string value) - { - if (value.StartsWith("-")) - { - value = value.Remove(0, 1); - } - - if (value.StartsWith("/")) - { - value = value.Remove(0, 1); - } - - return (string.Equals(switchName, value, StringComparison.InvariantCultureIgnoreCase)); - } - static bool IsInit(string singleArgument) { return singleArgument.Equals("init", StringComparison.InvariantCultureIgnoreCase);