Skip to content

Commit

Permalink
enhance command line with --simulate parameter (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgrassau committed Dec 16, 2024
1 parent 230a379 commit 89f7892
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,20 @@ public static void main(String[] args) {
cleanInteractively(null, ABAP.NEWEST_RELEASE, null, persistency.getStartupPath(), false, null, null, null, false);

} else {
if (commandLineArgs.action == CommandLineAction.SHOW_HELP) {
if (commandLineArgs.hasErrors()) {
// wrong or inconsistent command line args
System.err.println(commandLineArgs.errors);
System.err.println("");
System.err.flush();
System.out.print(CommandLineArgs.getHelp(persistency));

} else if (commandLineArgs.action == CommandLineAction.SHOW_HELP) {
System.out.print(CommandLineArgs.getHelp(persistency));

} else if (commandLineArgs.action == CommandLineAction.SHOW_VERSION) {
System.out.print(Program.PRODUCT_NAME + " " + Program.getVersion());

} else if (commandLineArgs.hasErrors()) {
if (commandLineArgs.hasErrors()) {
System.err.println(commandLineArgs.errors);
System.err.println("");
System.err.flush();
}
System.out.print(CommandLineArgs.getHelp(persistency));

} else {
} else { // if (commandLineArgs.action == CommandLineAction.CLEANUP)
// use application args for automatic cleanup
cleanAutomatically(commandLineArgs, System.out);
}
Expand Down Expand Up @@ -204,7 +203,7 @@ private static void cleanMultiSourceAutomatically(CommandLineArgs commandLineArg
for (String sourcePath : commandLineArgs.sourcePaths) {
String sourceCode = persistency.readAllTextFromFile(sourcePath);

CleanupResult result = cleanAutomatically(sourceCode, commandLineArgs.abapRelease, commandLineArgs.cleanupRange, null, profile, commandLineArgs.showStats, commandLineArgs.lineSeparator);
CleanupResult result = cleanAutomatically(sourceCode, commandLineArgs.abapRelease, commandLineArgs.cleanupRange, null, profile, commandLineArgs.showStatsOrUsedRules(), commandLineArgs.lineSeparator);
if (result == null) {
out.println("Cleanup for file " + sourcePath + " cancelled.");
continue;
Expand All @@ -220,7 +219,7 @@ private static void cleanMultiSourceAutomatically(CommandLineArgs commandLineArg
}

private static void cleanSingleSourceAutomatically(CommandLineArgs commandLineArgs, String sourceCode, PrintStream out, Profile profile) {
CleanupResult result = cleanAutomatically(commandLineArgs.sourceCode, commandLineArgs.abapRelease, commandLineArgs.cleanupRange, null, profile, commandLineArgs.showStats, commandLineArgs.lineSeparator);
CleanupResult result = cleanAutomatically(commandLineArgs.sourceCode, commandLineArgs.abapRelease, commandLineArgs.cleanupRange, null, profile, commandLineArgs.showStatsOrUsedRules(), commandLineArgs.lineSeparator);
if (result == null) {
out.println("Cleanup cancelled.");
return;
Expand All @@ -247,7 +246,7 @@ private static void writeCleanUpResult(CommandLineArgs commandLineArgs, PrintStr
}

// write statistics and/or used cleanup rules, if requested
if (commandLineArgs.showStats || commandLineArgs.showUsedRules) {
if (commandLineArgs.showStatsOrUsedRules()) {
// in case of multiple files, start with the current folder and file
if (!StringUtil.isNullOrEmpty(sourceFolderFile))
out.println(sourceFolderFile);
Expand All @@ -260,7 +259,9 @@ private static void writeCleanUpResult(CommandLineArgs commandLineArgs, PrintStr
out.println();
}

if (commandLineArgs.writesResultCodeToOutput()) {
if (commandLineArgs.simulate) {
// do nothing: this option is used if only the potential cleanup result is needed, using .showStatsOrUsedRules()
} else if (commandLineArgs.writesResultCodeToOutput()) {
out.print(output);
} else {
Persistency persistency = Persistency.get();
Expand Down
Loading

0 comments on commit 89f7892

Please sign in to comment.