Skip to content

Commit be43272

Browse files
authored
fix: switch default version property back to Version + add CLI option
Merge pull request #111 from skarpdev/bugfix-not-reading-version-tag
2 parents 1142e39 + 32b832d commit be43272

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

src/Program.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ static int Main(string[] args)
6565
"Set tag's name - default is 'v<version>'. Available variables: $projName, $oldVer, $newVer",
6666
CommandOptionType.SingleValue);
6767

68+
var projectFilePropertyName = commandLineApplication.Option(
69+
"-v | --version-property-name <property-name>",
70+
"Specify which tag from <PropertyGroup> to use as the version tag. Default is Version. Available values: Version, PackageVersion.",
71+
CommandOptionType.SingleValue);
72+
6873
commandLineApplication.OnExecute(() =>
6974
{
7075
try
@@ -103,7 +108,8 @@ static int Main(string[] args)
103108
buildMetaOption.Value(),
104109
prefixOption.Value(),
105110
commitMessage.Value(),
106-
vcsTag.Value()
111+
vcsTag.Value(),
112+
projectFilePropertyName.Value()
107113
);
108114
_cli.Execute(cliArgs);
109115

@@ -143,7 +149,8 @@ internal static VersionCliArgs GetVersionBumpFromRemainingArgs(
143149
string userSpecifiedBuildMeta,
144150
string preReleasePrefix,
145151
string commitMessage,
146-
string vcsTag
152+
string vcsTag,
153+
string projectFilePropertyName
147154
)
148155
{
149156
if (remainingArguments == null || !remainingArguments.Any())
@@ -162,8 +169,9 @@ string vcsTag
162169
BuildMeta = userSpecifiedBuildMeta,
163170
PreReleasePrefix = preReleasePrefix,
164171
CommitMessage = commitMessage,
165-
VersionControlTag = vcsTag,
172+
VersionControlTag = vcsTag
166173
};
174+
167175
var bump = VersionBump.Patch;
168176

169177
foreach (var arg in remainingArguments)
@@ -177,6 +185,11 @@ string vcsTag
177185

178186
args.VersionBump = bump;
179187
args.CsProjFilePath = userSpecifiedCsProjFilePath;
188+
189+
if (!string.IsNullOrEmpty(projectFilePropertyName))
190+
{
191+
args.ProjectFilePropertyName = Enum.Parse<ProjectFileProperty>(projectFilePropertyName, ignoreCase: true);
192+
}
180193

181194
return args;
182195
}

src/VersionCliArgs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public class VersionCliArgs
4444
public string VersionControlTag { get; set; }
4545

4646
/// <summary>
47-
/// Specify the Version-Tag that should be targeted. Default is PackageVersion
47+
/// Specify the Version-Tag that should be targeted. Default is Version.
4848
/// </summary>
49-
public ProjectFileProperty ProjectFilePropertyName { get; set; } = ProjectFileProperty.PackageVersion;
49+
public ProjectFileProperty ProjectFilePropertyName { get; set; } = ProjectFileProperty.Version;
5050
}
5151
}

test/ProgramTest.cs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Text;
4-
using FakeItEasy;
5-
using Microsoft.Extensions.CommandLineUtils;
6-
using Microsoft.VisualStudio.TestPlatform.TestHost;
3+
using Skarp.Version.Cli.CsProj;
74
using Xunit;
85

96
namespace Skarp.Version.Cli.Test
@@ -21,7 +18,7 @@ public class ProgramTest
2118
[InlineData("1.0.1-0", VersionBump.Specific)]
2219
[InlineData("1.0.1-0+master", VersionBump.Specific)]
2320
[InlineData("1.0.1-alpha.43+4432fsd", VersionBump.Specific)]
24-
public void GetVersionBumpFromRemaingArgsWork(string strVersionBump, VersionBump expectedBump)
21+
public void GetVersionBumpFromRemainingArgsWork(string strVersionBump, VersionBump expectedBump)
2522
{
2623
var args = Program.GetVersionBumpFromRemainingArgs(
2724
new List<string>() {strVersionBump},
@@ -32,6 +29,7 @@ public void GetVersionBumpFromRemaingArgsWork(string strVersionBump, VersionBump
3229
string.Empty,
3330
string.Empty,
3431
string.Empty,
32+
string.Empty,
3533
string.Empty
3634
);
3735
Assert.Equal(expectedBump, args.VersionBump);
@@ -54,6 +52,7 @@ public void Get_version_bump_throws_on_missing_value()
5452
string.Empty,
5553
string.Empty,
5654
string.Empty,
55+
string.Empty,
5756
string.Empty
5857
)
5958
);
@@ -77,12 +76,55 @@ public void Get_version_bump_throws_on_invalid_value()
7776
string.Empty,
7877
string.Empty,
7978
string.Empty,
79+
string.Empty,
8080
string.Empty
8181
)
8282
);
8383
Assert.Contains($"Invalid SemVer version string: {invalidVersion}",
8484
ex.Message);
8585
Assert.Equal("versionString", ex.ParamName);
8686
}
87+
88+
[Fact]
89+
public void DefaultsToReadingVersionStringFromVersionProperty()
90+
{
91+
var args = Program.GetVersionBumpFromRemainingArgs(
92+
new List<string>() {"patch"},
93+
OutputFormat.Text,
94+
true,
95+
true,
96+
string.Empty,
97+
string.Empty,
98+
string.Empty,
99+
string.Empty,
100+
string.Empty,
101+
string.Empty
102+
);
103+
104+
Assert.Equal(ProjectFileProperty.Version, args.ProjectFilePropertyName);
105+
}
106+
107+
[Theory]
108+
[InlineData(null, ProjectFileProperty.Version)]
109+
[InlineData("", ProjectFileProperty.Version)]
110+
[InlineData("verSION", ProjectFileProperty.Version)]
111+
[InlineData("packageversion", ProjectFileProperty.PackageVersion)]
112+
public void CanOverrideTheVersionPropertyName(string input, ProjectFileProperty expected)
113+
{
114+
var args = Program.GetVersionBumpFromRemainingArgs(
115+
new List<string>() {"patch"},
116+
OutputFormat.Text,
117+
true,
118+
true,
119+
string.Empty,
120+
string.Empty,
121+
string.Empty,
122+
string.Empty,
123+
string.Empty,
124+
input
125+
);
126+
127+
Assert.Equal(expected, args.ProjectFilePropertyName);
128+
}
87129
}
88130
}

0 commit comments

Comments
 (0)