Skip to content

Commit f2e4010

Browse files
authored
Merge pull request #1 from LarsReinken/1509_Adapt_templates_adaption_tests_cleanup
removed exception that was used to differenciate between test and pro…
2 parents ce23101 + f947e50 commit f2e4010

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public void initAdaptTemplatesTest() throws URISyntaxException, IOException {
5050
@Test
5151
public void adaptTemplatesTest() throws Exception {
5252

53-
String args[] = new String[1];
53+
String args[] = new String[2];
5454
args[0] = "adapt-templates";
55+
args[1] = "--all";
5556

5657
execute(args, false);
5758

cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl;
1717

1818
import picocli.CommandLine.Command;
19+
import picocli.CommandLine.Option;
1920

2021
/**
2122
* This class handles the user defined template directory e.g. determining and obtaining the latest templates jar,
@@ -30,6 +31,12 @@ public class AdaptTemplatesCommand extends CommandCommons {
3031
*/
3132
private static Logger LOG = LoggerFactory.getLogger(CobiGenCLI.class);
3233

34+
/**
35+
* If this options is enabled, all templates are unpacked.
36+
*/
37+
@Option(names = { "--all" }, negatable = true, description = MessagesConstants.UPDATE_ALL_DESCRIPTION)
38+
boolean adaptAll;
39+
3340
@Override
3441
public Integer doAction() throws Exception {
3542

@@ -74,9 +81,13 @@ private List<Path> getJarsToAdapt(TemplateAdapter templateAdapter, List<Path> te
7481
printJarsForSelection(templateAdapter, templateJars);
7582

7683
List<String> userSelection = new ArrayList<>();
77-
for (String templateSelection : ValidationUtils.getUserInput().split(",")) {
78-
userSelection.add(templateSelection);
79-
}
84+
85+
if (this.adaptAll)
86+
userSelection.add("0");
87+
else
88+
for (String templateSelection : ValidationUtils.getUserInput().split(",")) {
89+
userSelection.add(templateSelection);
90+
}
8091

8192
if (userSelection.contains("0")) {
8293
jarsToAdapt = templateJars;

cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ValidationUtils.java

-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.nio.file.Files;
55
import java.nio.file.Path;
66
import java.util.InputMismatchException;
7-
import java.util.NoSuchElementException;
87
import java.util.Scanner;
98

109
import org.slf4j.Logger;
@@ -131,14 +130,7 @@ public static void throwNoTriggersMatched(Path inputFile, boolean isJavaInput, b
131130
public static String getUserInput() {
132131

133132
String userInput = "";
134-
try {
135133
userInput = inputReader.nextLine();
136-
} catch (NoSuchElementException e) {
137-
// This Case is for the Adapt-templates Command to cover the next line in Test adaptTemplatesTest when no
138-
// UserInput can be scanned
139-
LOG.info("No User Input, By default All found templates will be adapted");
140-
userInput = "0";
141-
}
142134
return userInput;
143135
}
144136

0 commit comments

Comments
 (0)