7
7
public class CommandLineArgs {
8
8
private static final String LINE_SEP = System .lineSeparator ();
9
9
10
+ // options for help or version info
11
+ private static final String OPT_HELP_WINDOWS = "/?" ;
12
+ private static final String OPT_HELP_LINUX = "/man" ;
13
+ private static final String OPT_VERSION = "--version" ;
14
+
15
+ // options for cleanup
10
16
private static final String OPT_SOURCE_FILE = "--sourcefile" ;
11
17
private static final String OPT_SOURCE_CODE = "--source" ;
12
18
private static final String OPT_LINE_RANGE = "--linerange" ;
@@ -30,8 +36,6 @@ public class CommandLineArgs {
30
36
private static final String [] allOptions = new String [] { OPT_SOURCE_FILE , OPT_SOURCE_CODE , OPT_LINE_RANGE , OPT_TARGET_FILE , OPT_SOURCE_DIR , OPT_RECURSIVE , OPT_TARGET_DIR , OPT_FILE_FILTER , OPT_PROFILE , OPT_PROFILE_DATA , OPT_RELEASE , OPT_CRLF , OPT_OVERWRITE , OPT_PARTIAL_RESULT , OPT_STATS , OPT_USED_RULES };
31
37
32
38
private static final String EXECUTABLE_NAME = ".\\ abap-cleanerc.exe" ;
33
- private static final String OPT_HELP_WINDOWS = "/?" ;
34
- private static final String OPT_HELP_LINUX = "/man" ;
35
39
private static final char LINE_RANGE_SEP = '-' ;
36
40
private static final String LINE_RANGE_EXAMPLE = "\" 20-35\" " ;
37
41
@@ -47,11 +51,20 @@ public class CommandLineArgs {
47
51
48
52
@ SuppressWarnings ("unused" )
49
53
public static CommandLineArgs create (Persistency persistency , String [] args ) {
54
+ final String LINE_SEP = System .lineSeparator ();
55
+
50
56
if (args == null || args .length == 0 )
51
57
return null ;
52
58
53
- final String LINE_SEP = System .lineSeparator ();
54
-
59
+ // check whether help or version info is requested
60
+ if (args .length == 1 && (args [0 ].equals (OPT_HELP_WINDOWS ) || args [0 ].equals (OPT_HELP_LINUX ))) {
61
+ return new CommandLineArgs (CommandLineAction .SHOW_HELP );
62
+
63
+ } else if (args .length == 1 && args [0 ].equals (OPT_VERSION )) {
64
+ return new CommandLineArgs (CommandLineAction .SHOW_VERSION );
65
+ }
66
+
67
+ // in all other cases, cleanup is requested:
55
68
String sourceCode = null ;
56
69
String targetPath = null ;
57
70
CleanupRange cleanupRange = null ;
@@ -153,9 +166,6 @@ public static CommandLineArgs create(Persistency persistency, String[] args) {
153
166
} else if (arg .equals (OPT_USED_RULES )) {
154
167
showUsedRules = true ;
155
168
156
- } else if (arg .equals (OPT_HELP_WINDOWS ) || arg .equals (OPT_HELP_LINUX )) {
157
- showHelp = true ;
158
-
159
169
} else if (arg .equals (OPT_FILE_FILTER )) {
160
170
fileFilter = nextArg ;
161
171
@@ -216,10 +226,22 @@ public static String getHelp(Persistency persistency) {
216
226
217
227
StringBuilder sb = new StringBuilder ();
218
228
219
- String usagePrefix = " " + EXECUTABLE_NAME ;
229
+ String usagePrefix = " " + EXECUTABLE_NAME ;
220
230
String spacePrefix = StringUtil .repeatChar (' ' , usagePrefix .length ());
221
231
222
- sb .append ("Usage for single file:" );
232
+ sb .append ("Getting help and version information:" );
233
+ sb .append (LINE_SEP );
234
+ sb .append (usagePrefix );
235
+ sb .append (" " + OPT_HELP_WINDOWS );
236
+ sb .append (LINE_SEP );
237
+ sb .append (usagePrefix );
238
+ sb .append (" " + OPT_HELP_LINUX );
239
+ sb .append (LINE_SEP );
240
+ sb .append (usagePrefix );
241
+ sb .append (" " + OPT_VERSION );
242
+ sb .append (LINE_SEP + LINE_SEP );
243
+
244
+ sb .append ("Cleanup of single file:" );
223
245
sb .append (LINE_SEP );
224
246
sb .append (usagePrefix );
225
247
sb .append (" {" + OPT_SOURCE_FILE + " sourcefile" );
@@ -242,7 +264,7 @@ public static String getHelp(Persistency persistency) {
242
264
sb .append (" [" + OPT_USED_RULES + "]" );
243
265
sb .append (LINE_SEP + LINE_SEP );
244
266
245
- sb .append ("Example for single file:" );
267
+ sb .append ("Example for cleanup of single file:" );
246
268
sb .append (LINE_SEP );
247
269
sb .append (usagePrefix );
248
270
sb .append (" " + OPT_SOURCE_FILE + " \" CL_ANY_CLASS.txt\" " );
@@ -255,7 +277,7 @@ public static String getHelp(Persistency persistency) {
255
277
sb .append (" " + OPT_USED_RULES );
256
278
sb .append (LINE_SEP + LINE_SEP );
257
279
258
- sb .append ("Usage for multiple files:" );
280
+ sb .append ("Cleanup of multiple files:" );
259
281
sb .append (LINE_SEP );
260
282
sb .append (usagePrefix );
261
283
sb .append (" " + OPT_SOURCE_DIR + " sourcedir" );
@@ -276,7 +298,7 @@ public static String getHelp(Persistency persistency) {
276
298
sb .append (" [" + OPT_USED_RULES + "]" );
277
299
sb .append (LINE_SEP + LINE_SEP );
278
300
279
- sb .append ("Example for multiple files:" );
301
+ sb .append ("Example for cleanup of multiple files:" );
280
302
sb .append (LINE_SEP );
281
303
sb .append (usagePrefix );
282
304
sb .append (" " + OPT_SOURCE_DIR + " \" C:\\ temp\\ source\" " );
@@ -288,7 +310,7 @@ public static String getHelp(Persistency persistency) {
288
310
sb .append (" " + OPT_OVERWRITE );
289
311
sb .append (LINE_SEP + LINE_SEP );
290
312
291
- sb .append ("Options: " );
313
+ sb .append ("Options for cleanup : " );
292
314
sb .append (LINE_SEP );
293
315
sb .append (getOptionHelp (OPT_SOURCE_FILE , "File name of an ABAP source file which is input to the cleanup." ));
294
316
sb .append (getOptionHelp (OPT_SOURCE_CODE , "ABAP source code which is input to the cleanup." ));
@@ -337,6 +359,7 @@ private static String getOptionsLinePrefix(String option) {
337
359
338
360
// -------------------------------------------------------------------------
339
361
362
+ public final CommandLineAction action ;
340
363
public final String sourceCode ;
341
364
public final CleanupRange cleanupRange ;
342
365
public final String targetPath ;
@@ -354,15 +377,38 @@ private static String getOptionsLinePrefix(String option) {
354
377
public final boolean showStats ;
355
378
public final boolean showUsedRules ;
356
379
public final String errors ;
357
- public final boolean showHelp ;
358
380
359
381
public boolean hasErrors () { return !StringUtil .isNullOrEmpty (errors ); }
360
382
361
383
public boolean isInSingleSourceMode () { return sourceDir == null ; }
362
384
363
385
public boolean writesResultCodeToOutput () { return isInSingleSourceMode () && StringUtil .isNullOrEmpty (targetPath ); }
364
386
387
+ private CommandLineArgs (CommandLineAction action ) {
388
+ this .action = action ;
389
+
390
+ this .sourceCode = null ;
391
+ this .targetPath = null ;
392
+ this .cleanupRange = null ;
393
+
394
+ this .sourcePaths = null ;
395
+ this .sourceDir = null ;
396
+ this .targetDir = null ;
397
+
398
+ this .profileData = null ;
399
+ this .abapRelease = null ;
400
+
401
+ this .lineSeparator = null ;
402
+ this .overwrite = false ;
403
+ this .partialResult = false ;
404
+ this .showStats = false ;
405
+ this .showUsedRules = false ;
406
+ this .errors = null ;
407
+ }
408
+
365
409
private CommandLineArgs (String sourceCode , String targetPath , CleanupRange cleanupRange , String profileData , String abapRelease , String lineSeparator , boolean overwrite , boolean partialResult , boolean showStats , boolean showUsedRules , String errors , boolean showHelp ) {
410
+ this .action = CommandLineAction .CLEANUP ;
411
+
366
412
this .sourceCode = sourceCode ;
367
413
this .targetPath = targetPath ;
368
414
this .cleanupRange = cleanupRange ;
@@ -380,11 +426,11 @@ private CommandLineArgs(String sourceCode, String targetPath, CleanupRange clean
380
426
this .showStats = showStats ;
381
427
this .showUsedRules = showUsedRules ;
382
428
this .errors = errors ;
383
- this .showHelp = showHelp ;
384
-
385
429
}
386
430
387
431
private CommandLineArgs (String sourceDir , String [] sourcePaths , String targetDir , String profileData , String abapRelease , String lineSeparator , boolean overwrite , boolean showStats , boolean showUsedRules , String errors , boolean showHelp ) {
432
+ this .action = CommandLineAction .CLEANUP ;
433
+
388
434
this .sourceCode = null ;
389
435
this .cleanupRange = null ;
390
436
this .targetPath = null ;
@@ -402,6 +448,5 @@ private CommandLineArgs(String sourceDir, String[] sourcePaths, String targetDir
402
448
this .showStats = showStats ;
403
449
this .showUsedRules = showUsedRules ;
404
450
this .errors = errors ;
405
- this .showHelp = showHelp ;
406
451
}
407
452
}
0 commit comments