Skip to content

Commit

Permalink
Support configuring multiple /overrideconfig options by adding mult…
Browse files Browse the repository at this point in the history
…iple instances of `/overrideconfig` (eg. `/overrideconfig tag-prefix=custom /overrideconfig assembly-versioning-scheme=MajorMinor`)
  • Loading branch information
Nenad Vicentic authored and arturcic committed Apr 12, 2021
1 parent cf8f98e commit c9821c2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
11 changes: 7 additions & 4 deletions docs/input/docs/usage/cli/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@ gitversion init Configuration utility for gitversion

## Override config

`/overrideconfig [key=value]` will override appropriate key from 'GitVersion.yml'.
`/overrideconfig [key=value]` will override appropriate `key` from 'GitVersion.yml'.

Multiple options are separated by semicolon: `key1=value1;key2=value2`.
To specify multiple options add multiple `/overrideconfig [key=value]` entries:
`/overrideconfig key1=value1 /overrideconfig key2=value2`.

To have **space characters** as a part of `value`, `value` has be enclosed with double quotes - `key="My value"`.

Double quote character inside of the double quoted `value` has to be be escaped with a backslash '\\' - `key="My \"escaped-quotes\""`.

If closing double-qoute character is missing, it will be implicitily added at the very end of the command line argument - `key="My Value;key2=2(")`.

Following options are supported:
1. `assembly-file-versioning-format`
1. `assembly-file-versioning-scheme`
Expand Down Expand Up @@ -152,6 +151,10 @@ Will pickup up environment variable `BUILD_NUMBER` or fallback to zero for assem

Will use only major and minor version numbers for assembly version. Assembly build and revision numbers will be 0 (e.g. `1.2.0.0`)

### Example: How to override multiple configuration options

`GitVersion.exe /output json /overrideconfig tag-prefix=custom /overrideconfig assembly-versioning-scheme=MajorMinor`

### Example: How to override configuration option 'update-build-number'

`GitVersion.exe /output json /overrideconfig update-build-number=true`
Expand Down
10 changes: 5 additions & 5 deletions src/GitVersion.App.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,30 +559,30 @@ private static IEnumerable<TestCaseData> OverrideconfigWithSingleOptionTestData(
[TestCaseSource(nameof(OverrideconfigWithMultipleOptionsTestData))]
public void OverrideconfigWithMultipleOptions(string options, Config expected)
{
var arguments = argumentParser.ParseArguments($"/overrideconfig {options}");
var arguments = argumentParser.ParseArguments(options);
arguments.OverrideConfig.ShouldBeEquivalentTo(expected);
}

private static IEnumerable<TestCaseData> OverrideconfigWithMultipleOptionsTestData()
{
yield return new TestCaseData(
"tag-prefix=sample;assembly-versioning-scheme=MajorMinor",
"/overrideconfig tag-prefix=sample /overrideconfig assembly-versioning-scheme=MajorMinor",
new Config
{
TagPrefix = "sample",
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinor,
}
);
);
yield return new TestCaseData(
"tag-prefix=sample;assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"",
"/overrideconfig tag-prefix=sample /overrideconfig assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"",
new Config
{
TagPrefix = "sample",
AssemblyVersioningFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}"
}
);
yield return new TestCaseData(
"tag-prefix=sample;assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\";update-build-number=true;assembly-versioning-scheme=MajorMinorPatchTag;mode=ContinuousDelivery;tag-pre-release-weight=4",
"/overrideconfig tag-prefix=sample /overrideconfig assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\" /overrideconfig update-build-number=true /overrideconfig assembly-versioning-scheme=MajorMinorPatchTag /overrideconfig mode=ContinuousDelivery /overrideconfig tag-pre-release-weight=4",
new Config
{
TagPrefix = "sample",
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/QuotedStringHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static IEnumerable<TestCaseData> RemoveEmptyEntriesTestData()
}

[TestCaseSource(nameof(UnquoteTextTestData))]
public string UnquoteTextTextTests(string input)
public string UnquoteTextTests(string input)
{
return QuotedStringHelpers.UnquoteText(input);
}
Expand Down
12 changes: 4 additions & 8 deletions src/GitVersion.App/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private static bool ParseConfigArguments(Arguments arguments, string name, strin

if (name.IsSwitch("overrideconfig"))
{
ParseOverrideConfig(arguments, value);
ParseOverrideConfig(arguments, values);
return true;
}

Expand Down Expand Up @@ -422,19 +422,15 @@ private static void ParseVerbosity(Arguments arguments, string value)
}
}

private static void ParseOverrideConfig(Arguments arguments, string value)
private static void ParseOverrideConfig(Arguments arguments, string[] values)
{
// TODO: Split valu with regex so that double quotes are taken in consideration as well as escaped double quotes.
var keyValueOptions = QuotedStringHelpers.SplitUnquoted(value, ';');
if (keyValueOptions.Length == 0)
{
if (values == null || values.Length == 0)
return;
}

var parser = new OverrideConfigOptionParser();

// key=value
foreach (var keyValueOption in keyValueOptions)
foreach (var keyValueOption in values)
{
var keyAndValue = QuotedStringHelpers.SplitUnquoted(keyValueOption, '=');
if (keyAndValue.Length != 2)
Expand Down

0 comments on commit c9821c2

Please sign in to comment.