Skip to content

Commit ca422f7

Browse files
committed
Some small improvements
1 parent 2d2a6a2 commit ca422f7

10 files changed

+81
-18
lines changed

GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public static void Init(string workingDirectory, IFileSystem fileSystem)
4747
using (var stream = fileSystem.OpenWrite(configFilePath))
4848
using (var writer = new StreamWriter(stream))
4949
{
50+
Logger.WriteInfo("Saving config file");
5051
ConfigSerialiser.Write(config, writer);
52+
stream.Flush();
5153
}
5254
}
5355
}

GitVersionCore/Configuration/Wizard/ConfigInitWizardStep.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,46 @@ public abstract class ConfigInitWizardStep
77
{
88
public bool Apply(Queue<ConfigInitWizardStep> steps, Config config)
99
{
10+
Console.WriteLine();
1011
Console.WriteLine(GetPrompt(config));
1112
var input = Console.ReadLine();
1213
if (input == null)
1314
{
14-
return false;
15+
Console.WriteLine("Would you like to save changes? (y/n)");
16+
input = Console.ReadLine();
17+
if (input == null || input.ToLower() == "n") return false;
18+
if (input.ToLower() == "y")
19+
{
20+
steps.Clear();
21+
return true;
22+
}
23+
24+
InvalidResponse(steps);
25+
return true;
1526
}
1627
var resultWithDefaultApplied = string.IsNullOrEmpty(input) ? DefaultResult : input;
1728
var stepResult = HandleResult(resultWithDefaultApplied, steps, config);
1829
if (stepResult.InvalidResponse)
1930
{
20-
Console.WriteLine();
21-
Console.ForegroundColor = ConsoleColor.Red;
22-
Console.WriteLine("Invalid response!");
23-
Console.ResetColor();
24-
steps.Enqueue(this);
31+
InvalidResponse(steps);
32+
}
33+
else if (stepResult.Exit)
34+
{
35+
steps.Clear();
36+
return stepResult.Save;
2537
}
2638
return true;
2739
}
2840

41+
void InvalidResponse(Queue<ConfigInitWizardStep> steps)
42+
{
43+
Console.WriteLine();
44+
Console.ForegroundColor = ConsoleColor.Red;
45+
Console.WriteLine("Invalid response!");
46+
Console.ResetColor();
47+
steps.Enqueue(this);
48+
}
49+
2950
protected abstract StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config);
3051
protected abstract string GetPrompt(Config config);
3152
protected abstract string DefaultResult { get; }

GitVersionCore/Configuration/Wizard/ConfigureBranch.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3333

3434
protected override string GetPrompt(Config config)
3535
{
36-
return @"What would you like to change for config:
36+
return string.Format(@"What would you like to change for '{0}':
37+
3738
0) Back
38-
1) Branch Pre-release tag
39-
2) Branch Increment mode (per commit/after tag)";
39+
1) Branch Pre-release tag (Current: {1})
40+
2) Branch Increment mode (per commit/after tag) (Current: {2})", name, branchConfig.Tag, branchConfig.VersioningMode);
4041
}
4142

4243
protected override string DefaultResult

GitVersionCore/Configuration/Wizard/ConfigureBranches.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected override string GetPrompt(Config config)
3535
return @"Which branch would you like to configure:
3636
3737
0) Back
38-
" + OrderedBranches(config).Select((c, i) => string.Format("{0}) {1}", i + 1, c.Key));
38+
" + string.Join("\r\n", OrderedBranches(config).Select((c, i) => string.Format("{0}) {1}", i + 1, c.Key)));
3939
}
4040

4141
static IOrderedEnumerable<KeyValuePair<string, BranchConfig>> OrderedBranches(Config config)

GitVersionCore/Configuration/Wizard/EditConfigStep.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
1010
switch (result)
1111
{
1212
case "0":
13+
return StepResult.SaveAndExit();
14+
case "1":
15+
return StepResult.ExitWithoutSaving();
16+
case "2":
1317
steps.Enqueue(new ConfigureBranches());
1418
return StepResult.Ok();
15-
case "1":
19+
case "3":
1620
steps.Enqueue(new GlobalModeSetting(new EditConfigStep(), false));
1721
return StepResult.Ok();
18-
case "2":
22+
case "4":
1923
steps.Enqueue(new AssemblyVersioningSchemeSetting());
2024
return StepResult.Ok();
2125
}
@@ -24,11 +28,13 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
2428

2529
protected override string GetPrompt(Config config)
2630
{
27-
return @"What parts of the configuration would you like to edit?
31+
return string.Format(@"Which would you like to change?
2832
29-
0) Branch specific configuration
30-
1) Branch Increment mode (per commit/after tag)
31-
2) Assembly versioning scheme";
33+
0) Save changes
34+
1) Exit without saving
35+
2) Branch specific configuration
36+
3) Branch Increment mode (per commit/after tag) (Current: {0})
37+
4) Assembly versioning scheme (Current: {1})", config.VersioningMode, config.AssemblyVersioningScheme);
3238
}
3339

3440
protected override string DefaultResult
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace GitVersion
2+
{
3+
public class FinishedSetupStep : EditConfigStep
4+
{
5+
protected override string GetPrompt(Config config)
6+
{
7+
return "Questions are all done, you can now edit GitVersion's configuration further\r\n" + base.GetPrompt(config);
8+
}
9+
}
10+
}

GitVersionCore/Configuration/Wizard/GitFlowSetupStep.cs

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

55
public class GitFlowSetupStep : GlobalModeSetting
66
{
7-
public GitFlowSetupStep() : base(new ConfigureBranches(), true)
7+
public GitFlowSetupStep() : base(new FinishedSetupStep(), true)
88
{
99
}
1010

GitVersionCore/Configuration/Wizard/GitHubFlowStep.cs

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

55
public class GitHubFlowStep : GlobalModeSetting
66
{
7-
public GitHubFlowStep() : base(new ConfigureBranches(), true)
7+
public GitHubFlowStep() : base(new FinishedSetupStep(), true)
88
{
99
}
1010

GitVersionCore/Configuration/Wizard/StepResult.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@ public static StepResult InvalidResponseSelected()
1717
};
1818
}
1919

20+
public static StepResult SaveAndExit()
21+
{
22+
return new StepResult
23+
{
24+
Save = true,
25+
Exit = true
26+
};
27+
}
28+
29+
public static StepResult ExitWithoutSaving()
30+
{
31+
return new StepResult
32+
{
33+
Save = false,
34+
Exit = true
35+
};
36+
}
37+
38+
public bool Exit { get; private set; }
39+
40+
public bool Save { get; private set; }
41+
2042
public bool InvalidResponse { get; private set; }
2143
}
2244
}

GitVersionCore/GitVersionCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<Compile Include="Configuration\Wizard\ConfigureBranch.cs" />
8787
<Compile Include="Configuration\Wizard\ConfigureBranches.cs" />
8888
<Compile Include="Configuration\Wizard\EditConfigStep.cs" />
89+
<Compile Include="Configuration\Wizard\FinishedSetupStep.cs" />
8990
<Compile Include="Configuration\Wizard\GitFlowSetupStep.cs" />
9091
<Compile Include="Configuration\Wizard\GitHubFlowStep.cs" />
9192
<Compile Include="Configuration\Wizard\PickBranchingStrategy2Step.cs" />

0 commit comments

Comments
 (0)