diff --git a/gclc/src/main/java/fr/bigeon/gclc/command/CommandProvider.java b/gclc/src/main/java/fr/bigeon/gclc/command/CommandProvider.java index df77293..f532a0b 100644 --- a/gclc/src/main/java/fr/bigeon/gclc/command/CommandProvider.java +++ b/gclc/src/main/java/fr/bigeon/gclc/command/CommandProvider.java @@ -36,8 +36,8 @@ * Created on: Aug 6, 2014 */ package fr.bigeon.gclc.command; -import java.util.HashSet; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; import fr.bigeon.gclc.exception.CommandRunException; import fr.bigeon.gclc.exception.InvalidCommandName; @@ -53,12 +53,12 @@ public class CommandProvider implements ICommandProvider { /** The space character */ private static final String SPACE = " "; //$NON-NLS-1$ /** The commands map */ - protected final Set commands; + protected final List commands; /** Create a command provider */ public CommandProvider() { super(); - commands = new HashSet<>(); + commands = new ArrayList<>(); } /* (non-Javadoc) @@ -70,6 +70,9 @@ public class CommandProvider implements ICommandProvider { if (name == null || name.startsWith(MINUS) || name.contains(SPACE)) { throw new InvalidCommandName(); } + if (commands.contains(value)) { + return true; + } return commands.add(value); } diff --git a/gclc/src/main/java/fr/bigeon/gclc/prompt/CLIPrompter.java b/gclc/src/main/java/fr/bigeon/gclc/prompt/CLIPrompter.java index efd9c39..d84cf98 100644 --- a/gclc/src/main/java/fr/bigeon/gclc/prompt/CLIPrompter.java +++ b/gclc/src/main/java/fr/bigeon/gclc/prompt/CLIPrompter.java @@ -162,8 +162,11 @@ public class CLIPrompter { public static T promptChoice(ConsoleManager manager, List choices, Map choicesMap, String message, String cancel) throws IOException { - return choicesMap.get(choices.get( - promptChoice(manager, choices, message, cancel).intValue())); + Integer res = promptChoice(manager, choices, message, cancel); + if (res == null) { + return null; + } + return choicesMap.get(choices.get(res.intValue())); } /** @param manager the manager