Skip to content

Commit e69f11c

Browse files
author
Kevin Johnson
committed
Adds /version
The version of GitVersion is now displayed if the /version switch is provided. The version is also included in the help page.
1 parent 3a0765d commit e69f11c

File tree

7 files changed

+70
-2
lines changed

7 files changed

+70
-2
lines changed

src/GitVersionExe.Tests/HelpWriterTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public void AllArgsAreInHelp()
1616
{ "TargetBranch", "/b" },
1717
{ "LogFilePath" , "/l" },
1818
{ "DynamicRepositoryLocation" , "/dynamicRepoLocation" },
19-
{ "IsHelp", "/?" }
19+
{ "IsHelp", "/?" },
20+
{ "IsVersion", "/version" }
2021
};
2122
string helpText = null;
2223

src/GitVersionExe/ArgumentParser.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
6565
var values = switchesAndValues.GetValues(name);
6666
var value = values != null ? values.FirstOrDefault() : null;
6767

68+
if (name.IsSwitch("version"))
69+
{
70+
EnsureArgumentValueCount(values);
71+
arguments.IsVersion = true;
72+
continue;
73+
}
74+
6875
if (name.IsSwitch("l"))
6976
{
7077
EnsureArgumentValueCount(values);

src/GitVersionExe/Arguments.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public Arguments()
2828
public bool Init;
2929
public bool Diag;
3030

31+
public bool IsVersion;
3132
public bool IsHelp;
3233
public string LogFilePath;
3334
public string ShowVariable;

src/GitVersionExe/GitVersionExe.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<Compile Include="AssemblyInfo.cs" />
7373
<Compile Include="AssemblyInfoFileUpdate.cs" />
7474
<Compile Include="SpecifiedArgumentRunner.cs" />
75+
<Compile Include="VersionWriter.cs" />
7576
</ItemGroup>
7677
<ItemGroup>
7778
<None Include="app.config" />

src/GitVersionExe/HelpWriter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ public static void Write()
1111

1212
public static void WriteTo(Action<string> writeAction)
1313
{
14-
const string message = @"Use convention to derive a SemVer product version from a GitFlow or GitHub based repository.
14+
string version = string.Empty;
15+
VersionWriter.WriteTo(v => version = v);
16+
17+
string message = "GitVersion " + version + @"
18+
Use convention to derive a SemVer product version from a GitFlow or GitHub based repository.
1519
1620
GitVersion [path]
1721
1822
path The directory containing .git. If not defined current directory is used. (Must be first argument)
1923
init Configuration utility for gitversion
24+
/version Displays the version of GitVersion
2025
/diag Runs GitVersion with additional diagnostic information (requires git.exe to be installed)
2126
/h or /? Shows Help
2227

src/GitVersionExe/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ static int VerifyArgumentsAndRun()
5757
return 1;
5858
}
5959

60+
if (arguments.IsVersion)
61+
{
62+
VersionWriter.Write();
63+
return 0;
64+
}
65+
6066
if (arguments.IsHelp)
6167
{
6268
HelpWriter.Write();

src/GitVersionExe/VersionWriter.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using System.Linq;
5+
using System.Reflection;
6+
7+
class VersionWriter
8+
{
9+
/// <summary>
10+
/// Gets the xss version
11+
/// </summary>
12+
private static Version Version
13+
{
14+
get { return Assembly.GetExecutingAssembly().GetName().Version; }
15+
}
16+
17+
/// <summary>
18+
/// Gets the AssemblyInformationalVersion
19+
/// </summary>
20+
private static string InformationalVersion
21+
{
22+
get
23+
{
24+
var attribute = Assembly.GetExecutingAssembly()
25+
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)
26+
.FirstOrDefault() as AssemblyInformationalVersionAttribute;
27+
28+
if (attribute != null)
29+
{
30+
return attribute.InformationalVersion;
31+
}
32+
33+
return Version.ToString();
34+
}
35+
}
36+
37+
public static void Write()
38+
{
39+
WriteTo(Console.WriteLine);
40+
}
41+
42+
public static void WriteTo(Action<string> writeAction)
43+
{
44+
writeAction(InformationalVersion);
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)