@@ -108,78 +108,73 @@ private void PrintHelp()
108
108
109
109
WriteLine ( ) ;
110
110
111
- WriteHeader ( " Examples:" ) ;
111
+ PrintExamples ( GetTasks ( ) . SelectMany ( task => task . HelpInfo . Examples ) ) ;
112
112
113
- WritePrefix ( ) ;
114
- Write ( CallScriptName + " " ) ;
115
- WriteTask ( "restore" ) ;
116
- WriteLine ( ) ;
113
+ PrintOptions ( baseOptions ) ;
117
114
118
- WritePrefix ( ) ;
119
- Write ( CallScriptName + " " ) ;
120
- WriteTask ( "build " ) ;
121
- WriteOption ( "/p:" ) ;
122
- WriteArg ( "Configuration" ) ;
123
- WriteOption ( "=" ) ;
124
- WriteArg ( "Debug" ) ;
125
- WriteLine ( ) ;
115
+ WriteHeader ( "Tasks:" ) ;
116
+ var taskWidth = GetTaskNames ( ) . Max ( name => name . Length ) + 3 ;
117
+ foreach ( var ( taskName , taskDescription , _) in GetTasks ( ) )
118
+ {
119
+ if ( taskName . Equals ( "Default" , StringComparison . OrdinalIgnoreCase ) )
120
+ continue ;
126
121
127
- WritePrefix ( ) ;
128
- Write ( CallScriptName + " " ) ;
129
- WriteTask ( "pack " ) ;
130
- WriteOption ( "/p:" ) ;
131
- WriteArg ( "VersionPrefix" ) ;
132
- WriteOption ( "=" ) ;
133
- WriteArg ( "0.1.1729" ) ;
134
- WriteOption ( " /p:" ) ;
135
- WriteArg ( "VersionSuffix" ) ;
136
- WriteOption ( "=" ) ;
137
- WriteArg ( "preview" ) ;
138
- WriteLine ( ) ;
122
+ WriteTask ( " " + taskName . PadRight ( taskWidth ) ) ;
123
+ Write ( taskDescription ) ;
139
124
140
- WritePrefix ( ) ;
141
- Write ( CallScriptName + " " ) ;
142
- WriteTask ( "unit-tests " ) ;
143
- WriteOption ( "--exclusive --verbosity " ) ;
144
- WriteArg ( "Diagnostic" ) ;
145
- WriteLine ( ) ;
125
+ WriteLine ( ) ;
126
+ }
127
+ }
128
+
129
+ private void PrintTaskHelp ( string taskName )
130
+ {
131
+ var taskType = typeof ( BuildContext ) . Assembly
132
+ . GetTypes ( )
133
+ . Where ( type => type . IsSubclassOf ( typeof ( FrostingTask < BuildContext > ) ) && ! type . IsAbstract )
134
+ . First ( type => Is ( type . GetCustomAttribute < TaskNameAttribute > ( ) ? . Name , taskName ) ) ;
135
+ taskName = taskType . GetCustomAttribute < TaskNameAttribute > ( ) ! . Name ;
136
+ var taskDescription = taskType . GetCustomAttribute < TaskDescriptionAttribute > ( ) ? . Description ?? "" ;
137
+ var helpInfo = GetHelpInfo ( taskType ) ;
138
+
139
+ WriteHeader ( "Description:" ) ;
146
140
147
141
WritePrefix ( ) ;
148
- Write ( CallScriptName + " " ) ;
149
- WriteTask ( "docs-update " ) ;
150
- WriteOption ( "--depth " ) ;
151
- WriteArg ( "3" ) ;
142
+ WriteLine ( ! string . IsNullOrWhiteSpace ( taskDescription )
143
+ ? $ "Task '{ taskName } ': { taskDescription } "
144
+ : $ "Task '{ taskName } '") ;
145
+
146
+ if ( string . IsNullOrWhiteSpace ( helpInfo . Description ) )
147
+ foreach ( var line in helpInfo . Description . Split ( '\n ' , StringSplitOptions . RemoveEmptyEntries ) )
148
+ {
149
+ WritePrefix ( ) ;
150
+ WriteLine ( line . Trim ( ) ) ;
151
+ }
152
+
152
153
WriteLine ( ) ;
153
154
155
+ WriteHeader ( "Usage:" ) ;
156
+
154
157
WritePrefix ( ) ;
155
158
Write ( CallScriptName + " " ) ;
156
- WriteTask ( "docs-build ") ;
157
- WriteOption ( "--preview " ) ;
159
+ WriteTask ( taskName + " ") ;
160
+ WriteOption ( "[OPTIONS] " ) ;
158
161
WriteLine ( ) ;
159
162
160
163
WriteLine ( ) ;
161
164
162
- PrintOptions ( baseOptions ) ;
165
+ PrintExamples ( helpInfo . Examples ) ;
163
166
164
- WriteHeader ( "Tasks:" ) ;
165
- var taskWidth = GetTaskNames ( ) . Max ( name => name . Length ) + 3 ;
166
- foreach ( var ( taskName , taskDescription ) in GetTasks ( ) )
167
- {
168
- if ( taskName . Equals ( "Default" , StringComparison . OrdinalIgnoreCase ) )
169
- continue ;
167
+ PrintOptions ( helpInfo . Options . Concat ( baseOptions ) . ToArray ( ) ) ;
170
168
171
- if ( taskDescription . StartsWith ( "OBSOLETE" , StringComparison . OrdinalIgnoreCase ) )
172
- {
173
- WriteObsolete ( " " + taskName . PadRight ( taskWidth ) ) ;
174
- WriteObsolete ( taskDescription ) ;
175
- }
176
- else
169
+ if ( helpInfo . EnvironmentVariables . Any ( ) )
170
+ {
171
+ WriteHeader ( "Environment variables:" ) ;
172
+ foreach ( var variable in helpInfo . EnvironmentVariables )
177
173
{
178
- WriteTask ( " " + taskName . PadRight ( taskWidth ) ) ;
179
- Write ( taskDescription ) ;
174
+ WritePrefix ( ) ;
175
+ WriteOption ( variable ) ;
176
+ WriteLine ( ) ;
180
177
}
181
-
182
- WriteLine ( ) ;
183
178
}
184
179
}
185
180
@@ -242,88 +237,64 @@ int GetWidth(IOption option)
242
237
WriteLine ( ) ;
243
238
}
244
239
245
- private void PrintTaskHelp ( string taskName )
240
+ private void PrintExamples ( IEnumerable < Example > examples )
246
241
{
247
- var taskType = typeof ( BuildContext ) . Assembly
248
- . GetTypes ( )
249
- . Where ( type => type . IsSubclassOf ( typeof ( FrostingTask < BuildContext > ) ) && ! type . IsAbstract )
250
- . First ( type => Is ( type . GetCustomAttribute < TaskNameAttribute > ( ) ? . Name , taskName ) ) ;
251
- taskName = taskType . GetCustomAttribute < TaskNameAttribute > ( ) ! . Name ;
252
- var taskDescription = taskType . GetCustomAttribute < TaskDescriptionAttribute > ( ) ? . Description ?? "" ;
253
- var taskInstance = Activator . CreateInstance ( taskType ) ;
254
- var helpInfo = taskInstance is IHelpProvider helpProvider ? helpProvider . GetHelp ( ) : new HelpInfo ( ) ;
255
-
256
- WriteHeader ( "Description:" ) ;
257
-
258
- WritePrefix ( ) ;
259
- WriteLine ( $ "Task '{ taskName } '") ;
260
- if ( ! string . IsNullOrWhiteSpace ( taskDescription ) )
261
- {
262
- WritePrefix ( ) ;
263
- WriteLine ( taskDescription ) ;
264
- }
265
-
266
- if ( string . IsNullOrWhiteSpace ( helpInfo . Description ) )
267
- foreach ( var line in helpInfo . Description . Split ( '\n ' , StringSplitOptions . RemoveEmptyEntries ) )
268
- {
269
- WritePrefix ( ) ;
270
- WriteLine ( line . Trim ( ) ) ;
271
- }
272
-
273
- WriteLine ( ) ;
274
-
275
- WriteHeader ( "Usage:" ) ;
276
-
277
- WritePrefix ( ) ;
278
- Write ( CallScriptName + " " ) ;
279
- WriteTask ( taskName + " " ) ;
280
- WriteOption ( "[OPTIONS]" ) ;
281
- WriteLine ( ) ;
282
-
283
- WriteLine ( ) ;
284
-
285
242
WriteHeader ( "Examples:" ) ;
286
243
287
- WritePrefix ( ) ;
288
- Write ( ScriptName + " " ) ;
289
- WriteTask ( taskName ) ;
290
- WriteLine ( ) ;
291
-
292
- WriteLine ( ) ;
293
-
294
- PrintOptions ( helpInfo . Options . Concat ( baseOptions ) . ToArray ( ) ) ;
295
-
296
- if ( helpInfo . EnvironmentVariables . Any ( ) )
244
+ foreach ( var example in examples )
297
245
{
298
- WriteHeader ( "Environment variables:" ) ;
299
- foreach ( var variable in helpInfo . EnvironmentVariables )
246
+ WritePrefix ( ) ;
247
+ Write ( CallScriptName + " " ) ;
248
+ WriteTask ( example . TaskName + " " ) ;
249
+ foreach ( var ( name , value , isMsBuild ) in example . Arguments )
300
250
{
301
- WritePrefix ( ) ;
302
- WriteOption ( variable ) ;
251
+ if ( isMsBuild )
252
+ {
253
+ WriteOption ( "/p:" ) ;
254
+ WriteArg ( name ) ;
255
+ WriteOption ( "=" ) ;
256
+ WriteArg ( value + " " ) ;
257
+ }
258
+ else
259
+ {
260
+ WriteOption ( name + " " ) ;
261
+ if ( value != null )
262
+ WriteArg ( value + " " ) ;
263
+ }
303
264
}
304
265
305
266
WriteLine ( ) ;
306
267
}
268
+
269
+ WriteLine ( ) ;
307
270
}
308
271
309
272
private static HashSet < string > GetTaskNames ( )
310
273
{
311
274
return GetTasks ( ) . Select ( task => task . Name ) . ToHashSet ( StringComparer . OrdinalIgnoreCase ) ;
312
275
}
313
276
314
- private static List < ( string Name , string Description ) > GetTasks ( )
277
+ private static List < ( string Name , string Description , HelpInfo HelpInfo ) > GetTasks ( )
315
278
{
316
279
return typeof ( BuildContext ) . Assembly
317
280
. GetTypes ( )
318
281
. Where ( type => type . IsSubclassOf ( typeof ( FrostingTask < BuildContext > ) ) && ! type . IsAbstract )
319
282
. Select ( type => (
320
283
Name : type . GetCustomAttribute < TaskNameAttribute > ( ) ? . Name ?? "" ,
321
- Description : type . GetCustomAttribute < TaskDescriptionAttribute > ( ) ? . Description ?? ""
284
+ Description : type . GetCustomAttribute < TaskDescriptionAttribute > ( ) ? . Description ?? "" ,
285
+ HelpInfo : GetHelpInfo ( type )
322
286
) )
323
287
. Where ( task => task . Name != "" )
324
288
. ToList ( ) ;
325
289
}
326
290
291
+ private static HelpInfo GetHelpInfo ( Type taskType )
292
+ {
293
+ return Activator . CreateInstance ( taskType ) is IHelpProvider helpProvider
294
+ ? helpProvider . GetHelp ( )
295
+ : new HelpInfo ( ) ;
296
+ }
297
+
327
298
private static bool Is ( string ? arg , params string [ ] values ) =>
328
299
values . Any ( value => value . Equals ( arg , StringComparison . OrdinalIgnoreCase ) ) ;
329
300
0 commit comments