Skip to content

Commit

Permalink
This is what the updateassemblyinfo should be like, for GitTools#428
Browse files Browse the repository at this point in the history
But this is not backwards compatible.
  • Loading branch information
serra committed Aug 16, 2015
1 parent 901145d commit 99c844a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
22 changes: 9 additions & 13 deletions src/GitVersionExe.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,39 +193,35 @@ 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);
arguments.UpdateAssemblyInfo.ShouldBe(true);
}

[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");
}
Expand Down
32 changes: 14 additions & 18 deletions src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 99c844a

Please sign in to comment.