diff --git a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandTest.java b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandTest.java index 9f4026da4e..f98e293cc1 100644 --- a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandTest.java +++ b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandTest.java @@ -50,8 +50,9 @@ public void initAdaptTemplatesTest() throws URISyntaxException, IOException { @Test public void adaptTemplatesTest() throws Exception { - String args[] = new String[1]; + String args[] = new String[2]; args[0] = "adapt-templates"; + args[1] = "--all"; execute(args, false); diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java index 2f63360f86..93b1b69d02 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java @@ -16,6 +16,7 @@ import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl; import picocli.CommandLine.Command; +import picocli.CommandLine.Option; /** * 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 { */ private static Logger LOG = LoggerFactory.getLogger(CobiGenCLI.class); + /** + * If this options is enabled, all templates are unpacked. + */ + @Option(names = { "--all" }, negatable = true, description = MessagesConstants.UPDATE_ALL_DESCRIPTION) + boolean adaptAll; + @Override public Integer doAction() throws Exception { @@ -74,9 +81,13 @@ private List getJarsToAdapt(TemplateAdapter templateAdapter, List te printJarsForSelection(templateAdapter, templateJars); List userSelection = new ArrayList<>(); - for (String templateSelection : ValidationUtils.getUserInput().split(",")) { - userSelection.add(templateSelection); - } + + if (this.adaptAll) + userSelection.add("0"); + else + for (String templateSelection : ValidationUtils.getUserInput().split(",")) { + userSelection.add(templateSelection); + } if (userSelection.contains("0")) { jarsToAdapt = templateJars; diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ValidationUtils.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ValidationUtils.java index 018b2254a3..bead649d10 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ValidationUtils.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/ValidationUtils.java @@ -4,7 +4,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.InputMismatchException; -import java.util.NoSuchElementException; import java.util.Scanner; import org.slf4j.Logger; @@ -131,14 +130,7 @@ public static void throwNoTriggersMatched(Path inputFile, boolean isJavaInput, b public static String getUserInput() { String userInput = ""; - try { userInput = inputReader.nextLine(); - } catch (NoSuchElementException e) { - // This Case is for the Adapt-templates Command to cover the next line in Test adaptTemplatesTest when no - // UserInput can be scanned - LOG.info("No User Input, By default All found templates will be adapted"); - userInput = "0"; - } return userInput; }