| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | |
| | | /** |
| | | * This class defines a variant of the argument parser that can be used with applications that use subcommands to |
| | |
| | | */ |
| | | public class SubCommandArgumentParser extends ArgumentParser { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | private static final String INDENT = " "; |
| | | |
| | | /** The arguments that will be used to trigger the display of usage information for groups of sub-commands. */ |
| | | private final Map<Argument, Collection<SubCommand>> usageGroupArguments = |
| | | new HashMap<Argument, Collection<SubCommand>>(); |
| | | /** The set of unnamed trailing arguments that were provided for this parser. */ |
| | | private final ArrayList<String> trailingArguments = new ArrayList<String>(); |
| | | |
| | | /** The set of global arguments defined for this parser, referenced by short ID. */ |
| | | private final Map<Character, Argument> globalShortIDMap = new HashMap<Character, Argument>(); |
| | |
| | | /** The set of subcommands defined for this parser, referenced by subcommand name. */ |
| | | private final SortedMap<String, SubCommand> subCommands = new TreeMap<String, SubCommand>(); |
| | | |
| | | /** The raw set of command-line arguments that were provided. */ |
| | | private String[] rawArguments; |
| | | /**The subcommand requested by the user as part of the command-line arguments. */ |
| | | private SubCommand subCommand; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * Retrieves the raw set of arguments that were provided. |
| | | * |
| | | * @return The raw set of arguments that were provided, or <CODE>null</CODE> if the argument list has not yet been |
| | | * parsed. |
| | | */ |
| | | @Override |
| | | public String[] getRawArguments() { |
| | | return rawArguments; |
| | | } |
| | | |
| | | /** |
| | | * Adds the provided argument to the set of global arguments handled by this parser. |
| | | * |
| | | * @param argument |
| | |
| | | */ |
| | | @Override |
| | | public void parseArguments(String[] rawArguments, Properties argumentProperties) throws ArgumentException { |
| | | this.rawArguments = rawArguments; |
| | | setRawArguments(rawArguments); |
| | | this.subCommand = null; |
| | | this.trailingArguments.clear(); |
| | | final ArrayList<String> trailingArguments = getTrailingArguments(); |
| | | trailingArguments.clear(); |
| | | setUsageOrVersionDisplayed(false); |
| | | |
| | | boolean inTrailingArgs = false; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Retrieves the set of unnamed trailing arguments that were provided on the command line. |
| | | * |
| | | * @return The set of unnamed trailing arguments that were provided on the command line. |
| | | */ |
| | | @Override |
| | | public ArrayList<String> getTrailingArguments() { |
| | | return trailingArguments; |
| | | } |
| | | |
| | | /** |
| | | * Adds the provided subcommand to this argument parser. This is only intended for use by the |
| | | * <CODE>SubCommand</CODE> constructor and does not do any validation of its own to ensure that there are no |
| | | * conflicts with the subcommand or any of its arguments. |