@@ -50,71 +50,7 @@ private int VerifyArgumentsAndRun(Arguments arguments)
50
50
{
51
51
try
52
52
{
53
- if ( arguments == null )
54
- {
55
- helpWriter . Write ( ) ;
56
- return 1 ;
57
- }
58
- var targetPath = arguments . TargetPath ;
59
-
60
- if ( arguments . IsVersion )
61
- {
62
- var assembly = Assembly . GetExecutingAssembly ( ) ;
63
- versionWriter . Write ( assembly ) ;
64
- return 0 ;
65
- }
66
-
67
- if ( arguments . IsHelp )
68
- {
69
- helpWriter . Write ( ) ;
70
- return 0 ;
71
- }
72
-
73
- if ( arguments . Diag )
74
- {
75
- arguments . NoCache = true ;
76
- arguments . Output . Add ( OutputType . BuildServer ) ;
77
- }
78
-
79
- #pragma warning disable CS0612 // Type or member is obsolete
80
- if ( ! string . IsNullOrEmpty ( arguments . Proj ) || ! string . IsNullOrEmpty ( arguments . Exec ) )
81
- #pragma warning restore CS0612 // Type or member is obsolete
82
- {
83
- arguments . Output . Add ( OutputType . BuildServer ) ;
84
- }
85
-
86
- var buildServer = buildServerResolver . Resolve ( ) ;
87
- arguments . NoFetch = arguments . NoFetch || buildServer != null && buildServer . PreventFetch ( ) ;
88
-
89
- ConfigureLogging ( arguments , log ) ;
90
-
91
- if ( arguments . Diag )
92
- {
93
- log . Info ( "Dumping commit graph: " ) ;
94
- LibGitExtensions . DumpGraph ( targetPath , mess => log . Info ( mess ) , 100 ) ;
95
- }
96
- if ( ! Directory . Exists ( targetPath ) )
97
- {
98
- log . Warning ( $ "The working directory '{ targetPath } ' does not exist.") ;
99
- }
100
- else
101
- {
102
- log . Info ( "Working directory: " + targetPath ) ;
103
- }
104
-
105
- VerifyConfiguration ( ) ;
106
-
107
- if ( arguments . Init )
108
- {
109
- configProvider . Init ( targetPath ) ;
110
- return 0 ;
111
- }
112
- if ( arguments . ShowConfig )
113
- {
114
- var config = configProvider . Provide ( targetPath ) ;
115
- Console . WriteLine ( config . ToString ( ) ) ;
116
- return 0 ;
117
- }
53
+ if ( HandleNonMainCommand ( arguments , out var exitCode ) ) return exitCode ;
118
54
119
55
execCommand . Execute ( ) ;
120
56
}
@@ -148,9 +84,84 @@ private int VerifyArgumentsAndRun(Arguments arguments)
148
84
return 0 ;
149
85
}
150
86
151
- private void VerifyConfiguration ( )
87
+ private bool HandleNonMainCommand ( Arguments arguments , out int exitCode )
152
88
{
89
+ if ( arguments == null )
90
+ {
91
+ helpWriter . Write ( ) ;
92
+ exitCode = 1 ;
93
+ return true ;
94
+ }
95
+
96
+ var targetPath = arguments . TargetPath ;
97
+
98
+ if ( arguments . IsVersion )
99
+ {
100
+ var assembly = Assembly . GetExecutingAssembly ( ) ;
101
+ versionWriter . Write ( assembly ) ;
102
+ exitCode = 0 ;
103
+ return true ;
104
+ }
105
+
106
+ if ( arguments . IsHelp )
107
+ {
108
+ helpWriter . Write ( ) ;
109
+ exitCode = 0 ;
110
+ return true ;
111
+ }
112
+
113
+ if ( arguments . Diag )
114
+ {
115
+ arguments . NoCache = true ;
116
+ arguments . Output . Add ( OutputType . BuildServer ) ;
117
+ }
118
+
119
+ #pragma warning disable CS0612 // Type or member is obsolete
120
+ if ( ! string . IsNullOrEmpty ( arguments . Proj ) || ! string . IsNullOrEmpty ( arguments . Exec ) )
121
+ #pragma warning restore CS0612 // Type or member is obsolete
122
+ {
123
+ arguments . Output . Add ( OutputType . BuildServer ) ;
124
+ }
125
+
126
+ var buildServer = buildServerResolver . Resolve ( ) ;
127
+ arguments . NoFetch = arguments . NoFetch || buildServer != null && buildServer . PreventFetch ( ) ;
128
+
129
+ ConfigureLogging ( arguments , log ) ;
130
+
131
+ if ( arguments . Diag )
132
+ {
133
+ log . Info ( "Dumping commit graph: " ) ;
134
+ LibGitExtensions . DumpGraph ( targetPath , mess => log . Info ( mess ) , 100 ) ;
135
+ }
136
+
137
+ if ( ! Directory . Exists ( targetPath ) )
138
+ {
139
+ log . Warning ( $ "The working directory '{ targetPath } ' does not exist.") ;
140
+ }
141
+ else
142
+ {
143
+ log . Info ( "Working directory: " + targetPath ) ;
144
+ }
145
+
153
146
configFileLocator . Verify ( gitPreparer ) ;
147
+
148
+ if ( arguments . Init )
149
+ {
150
+ configProvider . Init ( targetPath ) ;
151
+ exitCode = 0 ;
152
+ return true ;
153
+ }
154
+
155
+ if ( arguments . ShowConfig )
156
+ {
157
+ var config = configProvider . Provide ( targetPath ) ;
158
+ Console . WriteLine ( config . ToString ( ) ) ;
159
+ exitCode = 0 ;
160
+ return true ;
161
+ }
162
+
163
+ exitCode = 0 ;
164
+ return false ;
154
165
}
155
166
156
167
private static void ConfigureLogging ( Arguments arguments , ILog log )
0 commit comments