Skip to content

Commit 6071946

Browse files
committed
Extracted the program logic into a Run() method that returns the exit code which is then always set on the Environment.
1 parent 7b8fe32 commit 6071946

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

GitVersionExe/Program.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,24 @@ class Program
1414

1515
static void Main()
1616
{
17-
int? exitCode = null;
17+
var exitCode = Run();
1818

19+
if (Debugger.IsAttached)
20+
{
21+
Console.ReadKey();
22+
}
23+
24+
if (exitCode != 0)
25+
{
26+
// Dump log to console if we fail to complete successfully
27+
Console.Write(log.ToString());
28+
}
29+
30+
Environment.Exit(exitCode);
31+
}
32+
33+
static int Run()
34+
{
1935
try
2036
{
2137
Arguments arguments;
@@ -29,17 +45,19 @@ static void Main()
2945
Console.WriteLine("Failed to parse arguments: {0}", string.Join(" ", argumentsWithoutExeName));
3046

3147
HelpWriter.Write();
32-
return;
48+
return 0;
3349
}
3450

3551
if (arguments.IsHelp)
3652
{
3753
HelpWriter.Write();
38-
return;
54+
return 0;
3955
}
4056

4157
if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec))
58+
{
4259
arguments.Output = OutputType.BuildServer;
60+
}
4361

4462
ConfigureLogging(arguments);
4563

@@ -48,7 +66,7 @@ static void Main()
4866
if (string.IsNullOrEmpty(gitDirectory))
4967
{
5068
Console.Error.WriteLine("Failed to prepare or find the .git directory in path '{0}'", arguments.TargetPath);
51-
Environment.Exit(1);
69+
return 1;
5270
}
5371

5472
var workingDirectory = Directory.GetParent(gitDirectory).FullName;
@@ -119,33 +137,16 @@ static void Main()
119137
{
120138
var error = string.Format("An error occurred:\r\n{0}", exception.Message);
121139
Logger.WriteWarning(error);
122-
123-
exitCode = 1;
140+
return 1;
124141
}
125142
catch (Exception exception)
126143
{
127144
var error = string.Format("An unexpected error occurred:\r\n{0}", exception);
128145
Logger.WriteError(error);
129-
130-
exitCode = 1;
131-
}
132-
133-
if (Debugger.IsAttached)
134-
{
135-
Console.ReadKey();
136-
}
137-
138-
if (!exitCode.HasValue)
139-
{
140-
exitCode = 0;
141-
}
142-
else
143-
{
144-
// Dump log to console if we fail to complete successfully
145-
Console.Write(log.ToString());
146+
return 1;
146147
}
147148

148-
Environment.Exit(exitCode.Value);
149+
return 0;
149150
}
150151

151152
static IEnumerable<IBuildServer> GetApplicableBuildServers(Authentication authentication)

0 commit comments

Comments
 (0)