Skip to content

Commit ec248ba

Browse files
committed
reviewed classes/methods that are included in the public API
1 parent 7f147ed commit ec248ba

36 files changed

+128
-259
lines changed

src/GitVersion.App.Tests/ArgumentParserTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using GitVersion.Configuration;
22
using GitVersion.Core.Tests.Helpers;
3-
using GitVersion.Extensions;
43
using GitVersion.Helpers;
54
using GitVersion.Logging;
65
using GitVersion.VersionCalculation;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System.Text.RegularExpressions;
2+
using GitVersion.Helpers;
3+
4+
namespace GitVersion;
5+
6+
internal static class ArgumentParserExtensions
7+
{
8+
private static readonly string[] TrueValues = ["1", "true"];
9+
private static readonly string[] FalseValues = ["0", "false"];
10+
11+
public static bool IsTrue(this string? value) => TrueValues.Contains(value, StringComparer.OrdinalIgnoreCase);
12+
13+
public static bool IsFalse(this string? value) => FalseValues.Contains(value, StringComparer.OrdinalIgnoreCase);
14+
15+
public static bool IsValidPath(this string? path)
16+
{
17+
if (path == null)
18+
return false;
19+
20+
try
21+
{
22+
_ = PathHelper.GetFullPath(path);
23+
}
24+
catch
25+
{
26+
path = PathHelper.Combine(SysEnv.CurrentDirectory, path);
27+
28+
try
29+
{
30+
_ = PathHelper.GetFullPath(path);
31+
}
32+
catch
33+
{
34+
return false;
35+
}
36+
}
37+
38+
return Directory.Exists(path);
39+
}
40+
41+
public static bool IsSwitchArgument(this string? value)
42+
=> value != null
43+
&& (value.StartsWith('-') || value.StartsWith('/'))
44+
&& !Regex.Match(value, @"/\w+:").Success; //Exclude msbuild & project parameters in form /blah:, which should be parsed as values, not switch names.
45+
46+
public static bool IsSwitch(this string? value, string switchName)
47+
{
48+
if (value == null)
49+
return false;
50+
51+
if (value.StartsWith('-'))
52+
{
53+
value = value[1..];
54+
}
55+
56+
if (value.StartsWith('/'))
57+
{
58+
value = value[1..];
59+
}
60+
61+
return string.Equals(switchName, value, StringComparison.OrdinalIgnoreCase);
62+
}
63+
64+
public static bool IsHelp(this string singleArgument) => (singleArgument == "?") || singleArgument.IsSwitch("h") || singleArgument.IsSwitch("help") || singleArgument.IsSwitch("?");
65+
66+
public static bool ArgumentRequiresValue(this string argument, int argumentIndex)
67+
{
68+
var booleanArguments = new[] { "init", "updateassemblyinfo", "ensureassemblyinfo", "nofetch", "nonormalize", "nocache" };
69+
70+
var argumentMightRequireValue = !booleanArguments.Contains(argument[1..], StringComparer.OrdinalIgnoreCase);
71+
72+
// If this is the first argument that might be a target path, the argument starts with slash and we're on an OS that supports paths with slashes, the argument does not require a value.
73+
if (argumentMightRequireValue && argumentIndex == 0 && argument.StartsWith('/') && Path.DirectorySeparatorChar == '/' && argument.IsValidPath())
74+
return false;
75+
76+
return argumentMightRequireValue;
77+
}
78+
}

src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using GitVersion.Configuration;
33
using GitVersion.Configuration.Tests.Configuration;
44
using GitVersion.Core.Tests.Helpers;
5-
using GitVersion.Extensions;
65
using GitVersion.Helpers;
76
using GitVersion.Logging;
87
using GitVersion.VersionCalculation;

src/GitVersion.Configuration/EmptyConfigurationBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using GitVersion.Extensions;
21
using GitVersion.VersionCalculation;
32

43
namespace GitVersion.Configuration;

src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using GitVersion.Configuration;
22
using GitVersion.Core.Tests.Helpers;
3-
using GitVersion.Extensions;
43
using GitVersion.VersionCalculation;
54
using LibGit2Sharp;
65

src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using GitVersion.Configuration;
22
using GitVersion.Core.Tests.Helpers;
3-
using GitVersion.Extensions;
43
using LibGit2Sharp;
54

65
namespace GitVersion.Core.Tests.IntegrationTests;

src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using GitVersion.Configuration;
22
using GitVersion.Core.Tests.Helpers;
3-
using GitVersion.Extensions;
43
using LibGit2Sharp;
54

65
namespace GitVersion.Core.Tests.IntegrationTests;

src/GitVersion.Core.Tests/IntegrationTests/TrunkBasedDevelopmentScenarios.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using GitVersion.Configuration;
22
using GitVersion.Core.Tests.Helpers;
3-
using GitVersion.Extensions;
43
using GitVersion.VersionCalculation;
54

65
namespace GitVersion.Core.Tests.IntegrationTests;

src/GitVersion.Core/Agents/BuildAgentBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace GitVersion.Agents;
66

7-
public abstract class BuildAgentBase(IEnvironment environment, ILog log) : ICurrentBuildAgent
7+
internal abstract class BuildAgentBase(IEnvironment environment, ILog log) : ICurrentBuildAgent
88
{
99
protected readonly ILog Log = log;
1010
protected IEnvironment Environment { get; } = environment;

src/GitVersion.Core/Agents/IBuildAgent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public interface IBuildAgent
1414
void WriteIntegration(Action<string?> writer, GitVersionVariables variables, bool updateBuildNumber = true);
1515
}
1616

17-
public interface ICurrentBuildAgent : IBuildAgent { }
17+
public interface ICurrentBuildAgent : IBuildAgent;

0 commit comments

Comments
 (0)