Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
{
arguments.UpdateAssemblyInfo = false;
}
else if (!IsSwitchArgument(value))
{
arguments.UpdateAssemblyInfo = true;
arguments.UpdateAssemblyInfoFileName = value;
}
else
{
arguments.UpdateAssemblyInfo = true;
Expand Down Expand Up @@ -159,6 +164,11 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
return arguments;
}

static bool IsSwitchArgument(string value)
{
return value != null && value.StartsWith("-") || value.StartsWith("/");
}

static bool IsSwitch(string switchName, string value)
{
if (value.StartsWith("-"))
Expand Down
1 change: 1 addition & 0 deletions GitVersionExe/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public Arguments()
public string ExecArgs;

public bool UpdateAssemblyInfo;
public string UpdateAssemblyInfoFileName;
}
}
16 changes: 14 additions & 2 deletions GitVersionExe/AssemblyInfoFileUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, Dictionar
if (args.Output != OutputType.Json)
Console.WriteLine("Updating assembly info files");

var assemblyInfoFiles = Directory.GetFiles(workingDirectory, "AssemblyInfo.cs",
SearchOption.AllDirectories);
var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args);

foreach (var assemblyInfoFile in assemblyInfoFiles)
{
Expand All @@ -44,6 +43,19 @@ public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, Dictionar
}
}

static IEnumerable<string> GetAssemblyInfoFiles(string workingDirectory, Arguments args)
{
if (args.UpdateAssemblyInfoFileName != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just return Directory.GetFiles(workingDirectory, args.UpdateAssemblyInfoFileName ?? "AssemblyInfo.cs", SearchOption.AllDirectories);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this could work, I also did the Path.GetFullPath to handle both relative and absolute paths...
Though it also might be useful to provide a relative root directory, e.g. update all assemblyinfo.cs under this specific dir (and not in the entire repository)

{
if (File.Exists(args.UpdateAssemblyInfoFileName))
{
return new[] { Path.GetFullPath(args.UpdateAssemblyInfoFileName) };
}
}

return Directory.GetFiles(workingDirectory, "AssemblyInfo.cs", SearchOption.AllDirectories);
}

public void Dispose()
{
foreach (var restoreBackup in restoreBackupTasks)
Expand Down
30 changes: 28 additions & 2 deletions Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,37 @@ public void Unknown_argument_should_throw()
Assert.AreEqual("Could not parse command line parameter '-x'.", exception.Message);
}

[TestCase("-updateAssemblyInfo true")]
[TestCase("-updateAssemblyInfo 1")]
[TestCase("-updateAssemblyInfo -proj foo.sln")]
public void update_assembly_info_true(string command)
{
var arguments = ArgumentParser.ParseArguments(command);
arguments.UpdateAssemblyInfo.ShouldBe(true);
}

[TestCase("-updateAssemblyInfo false")]
[TestCase("-updateAssemblyInfo 0")]
public void update_assembly_info_false(string command)
{
var arguments = ArgumentParser.ParseArguments(command);
arguments.UpdateAssemblyInfo.ShouldBe(false);
}

[Test]
public void update_assembly_info_with_filename()
{
var arguments = ArgumentParser.ParseArguments("-updateAssemblyInfo CommonAssemblyInfo.cs");
arguments.UpdateAssemblyInfo.ShouldBe(true);
arguments.UpdateAssemblyInfoFileName.ShouldBe("CommonAssemblyInfo.cs");
}

[Test]
public void update_assembly_info()
public void update_assembly_info_with_relative_filename()
{
var arguments = ArgumentParser.ParseArguments("-updateAssemblyInfo -proj foo.sln");
var arguments = ArgumentParser.ParseArguments("-updateAssemblyInfo ..\\..\\CommonAssemblyInfo.cs");
arguments.UpdateAssemblyInfo.ShouldBe(true);
arguments.UpdateAssemblyInfoFileName.ShouldBe("..\\..\\CommonAssemblyInfo.cs");
}

[Test]
Expand Down