Skip to content

Commit 2d2a6a2

Browse files
committed
More options and steps in gitversion init
1 parent 4c0952c commit 2d2a6a2

17 files changed

+376
-67
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace GitVersion
2+
{
3+
using System.Collections.Generic;
4+
5+
public class AssemblyVersioningSchemeSetting : ConfigInitWizardStep
6+
{
7+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
8+
{
9+
switch (result)
10+
{
11+
case "0":
12+
steps.Enqueue(new EditConfigStep());
13+
return StepResult.Ok();
14+
case "1":
15+
config.AssemblyVersioningScheme = AssemblyVersioningScheme.Major;
16+
steps.Enqueue(new EditConfigStep());
17+
return StepResult.Ok();
18+
case "2":
19+
config.AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinor;
20+
steps.Enqueue(new EditConfigStep());
21+
return StepResult.Ok();
22+
case "3":
23+
config.AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
24+
steps.Enqueue(new EditConfigStep());
25+
return StepResult.Ok();
26+
case "4":
27+
config.AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag;
28+
steps.Enqueue(new EditConfigStep());
29+
return StepResult.Ok();
30+
}
31+
32+
return StepResult.InvalidResponseSelected();
33+
}
34+
35+
protected override string GetPrompt(Config config)
36+
{
37+
return @"What assembly versioning scheme do you want to use:
38+
39+
0) Back
40+
1) Major.0.0.0
41+
2) Major.Minor.0.0
42+
3) Major.Minor.Patch.0 (default)
43+
4) Major.Minor.Patch.TagCount (Allows different pre-release tags to cause assembly version to change)";
44+
}
45+
46+
protected override string DefaultResult
47+
{
48+
get { return "0"; }
49+
}
50+
}
51+
}

GitVersionCore/Configuration/Wizard/ConfigInitWizardStep.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public abstract class ConfigInitWizardStep
77
{
88
public bool Apply(Queue<ConfigInitWizardStep> steps, Config config)
99
{
10-
Console.WriteLine(Prompt);
10+
Console.WriteLine(GetPrompt(config));
1111
var input = Console.ReadLine();
1212
if (input == null)
1313
{
@@ -27,7 +27,7 @@ public bool Apply(Queue<ConfigInitWizardStep> steps, Config config)
2727
}
2828

2929
protected abstract StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config);
30-
protected abstract string Prompt { get; }
30+
protected abstract string GetPrompt(Config config);
3131
protected abstract string DefaultResult { get; }
3232
}
3333
}
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.Collections.Generic;
4+
5+
public class ConfigureBranch : ConfigInitWizardStep
6+
{
7+
string name;
8+
readonly BranchConfig branchConfig;
9+
10+
public ConfigureBranch(string name, BranchConfig branchConfig)
11+
{
12+
this.branchConfig = branchConfig;
13+
this.name = name;
14+
}
15+
16+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
17+
{
18+
switch (result)
19+
{
20+
case "0":
21+
steps.Enqueue(new ConfigureBranches());
22+
return StepResult.Ok();
23+
case "1":
24+
steps.Enqueue(new SetBranchTag(name, branchConfig));
25+
return StepResult.Ok();
26+
case "2":
27+
steps.Enqueue(new SetBranchIncrementMode(name, branchConfig));
28+
return StepResult.Ok();
29+
}
30+
31+
return StepResult.InvalidResponseSelected();
32+
}
33+
34+
protected override string GetPrompt(Config config)
35+
{
36+
return @"What would you like to change for config:
37+
0) Back
38+
1) Branch Pre-release tag
39+
2) Branch Increment mode (per commit/after tag)";
40+
}
41+
42+
protected override string DefaultResult
43+
{
44+
get { return "0"; }
45+
}
46+
}
47+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
7+
public class ConfigureBranches : ConfigInitWizardStep
8+
{
9+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
10+
{
11+
int parsed;
12+
if (int.TryParse(result, out parsed))
13+
{
14+
if (parsed == 0)
15+
{
16+
steps.Enqueue(new EditConfigStep());
17+
return StepResult.Ok();
18+
}
19+
20+
try
21+
{
22+
var foundBranch = OrderedBranches(config).ElementAt(parsed - 1);
23+
steps.Enqueue(new ConfigureBranch(foundBranch.Key, foundBranch.Value));
24+
return StepResult.Ok();
25+
}
26+
catch (ArgumentOutOfRangeException)
27+
{ }
28+
}
29+
30+
return StepResult.InvalidResponseSelected();
31+
}
32+
33+
protected override string GetPrompt(Config config)
34+
{
35+
return @"Which branch would you like to configure:
36+
37+
0) Back
38+
" + OrderedBranches(config).Select((c, i) => string.Format("{0}) {1}", i + 1, c.Key));
39+
}
40+
41+
static IOrderedEnumerable<KeyValuePair<string, BranchConfig>> OrderedBranches(Config config)
42+
{
43+
return config.Branches.OrderBy(b => b.Key);
44+
}
45+
46+
protected override string DefaultResult
47+
{
48+
get { return "0"; }
49+
}
50+
}
51+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace GitVersion
2+
{
3+
using System.Collections.Generic;
4+
using GitVersion.Configuration.Wizard.SetConfig;
5+
6+
public class EditConfigStep : ConfigInitWizardStep
7+
{
8+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
9+
{
10+
switch (result)
11+
{
12+
case "0":
13+
steps.Enqueue(new ConfigureBranches());
14+
return StepResult.Ok();
15+
case "1":
16+
steps.Enqueue(new GlobalModeSetting(new EditConfigStep(), false));
17+
return StepResult.Ok();
18+
case "2":
19+
steps.Enqueue(new AssemblyVersioningSchemeSetting());
20+
return StepResult.Ok();
21+
}
22+
return StepResult.Ok();
23+
}
24+
25+
protected override string GetPrompt(Config config)
26+
{
27+
return @"What parts of the configuration would you like to edit?
28+
29+
0) Branch specific configuration
30+
1) Branch Increment mode (per commit/after tag)
31+
2) Assembly versioning scheme";
32+
}
33+
34+
protected override string DefaultResult
35+
{
36+
get { return null; }
37+
}
38+
}
39+
}

GitVersionCore/Configuration/Wizard/ExpressSetupStep.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
namespace GitVersion
22
{
3-
using System.Collections.Generic;
3+
using Configuration.Wizard.SetConfig;
44

5-
public class GitFlowSetupStep : ConfigInitWizardStep
5+
public class GitFlowSetupStep : GlobalModeSetting
66
{
7-
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
7+
public GitFlowSetupStep() : base(new ConfigureBranches(), true)
88
{
9-
throw new System.NotImplementedException();
109
}
1110

12-
protected override string Prompt
11+
protected override string GetPrompt(Config config)
1312
{
14-
get { throw new System.NotImplementedException(); }
15-
}
16-
17-
protected override string DefaultResult
18-
{
19-
get { throw new System.NotImplementedException(); }
13+
return "By default GitVersion will only increment the version of the 'develop' branch every commit, all other branches will increment when tagged\r\n\r\n" + base.GetPrompt(config);
2014
}
2115
}
2216
}
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
namespace GitVersion
22
{
3-
using System.Collections.Generic;
3+
using Configuration.Wizard.SetConfig;
44

5-
public class GitHubFlowStep : ConfigInitWizardStep
5+
public class GitHubFlowStep : GlobalModeSetting
66
{
7-
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
7+
public GitHubFlowStep() : base(new ConfigureBranches(), true)
88
{
9-
throw new System.NotImplementedException();
109
}
1110

12-
protected override string Prompt
11+
protected override string GetPrompt(Config config)
1312
{
14-
get { throw new System.NotImplementedException(); }
15-
}
16-
17-
protected override string DefaultResult
18-
{
19-
get { throw new System.NotImplementedException(); }
13+
return "By default GitVersion will only increment the version when tagged\r\n\r\n" + base.GetPrompt(config);
2014
}
2115
}
2216
}

GitVersionCore/Configuration/Wizard/PickBranchingStrategy1Step.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
2323
return StepResult.InvalidResponseSelected();
2424
}
2525

26-
protected override string Prompt
26+
protected override string GetPrompt(Config config)
2727
{
28-
get { return @"GitVersion can try to recommend you a branching strategy based on a few questions.
28+
return @"GitVersion can try to recommend you a branching strategy based on a few questions.
2929
30-
Do you need to maintain mutliple versions of your application simultanously in production? (y/n)"; }
30+
Do you need to maintain mutliple versions of your application simultanously in production? (y/n)";
3131
}
3232

3333
protected override string DefaultResult

GitVersionCore/Configuration/Wizard/PickBranchingStrategy2Step.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
2626
return StepResult.InvalidResponseSelected();
2727
}
2828

29-
protected override string Prompt
29+
protected override string GetPrompt(Config config)
3030
{
31-
get { return "Do you stabilise releases while continuing work on the next version? (y/n)"; }
31+
return "Do you stabilise releases while continuing work on the next version? (y/n)";
3232
}
3333

3434
protected override string DefaultResult

0 commit comments

Comments
 (0)