@Test public void testEmptyParser() throws Exception { try { CLIParser parser = new CLIParser("ivory", new String[] {}); CLIParser.Command c = parser.parse(new String[] { "a" }); Assert.fail(); } catch (ParseException ex) { } }
public Command parse(String[] args) throws ParseException { if (args.length == 0) { throw new ParseException("missing sub-command"); } else { if (commands.containsKey(args[0])) { GnuParser parser = new GnuParser(); String[] minusCommand = new String[args.length - 1]; System.arraycopy(args, 1, minusCommand, 0, minusCommand.length); return new Command(args[0], parser.parse(commands.get(args[0]), minusCommand, commandWithArgs.get(args[0]))); } else { throw new ParseException(MessageFormat.format("invalid sub-command [{0}]", args[0])); } } }
CLIParser { public Command parse(String[] args) throws ParseException { if (args.length == 0) { throw new ParseException("missing sub-command"); } else { if (commands.containsKey(args[0])) { GnuParser parser = new GnuParser(); String[] minusCommand = new String[args.length - 1]; System.arraycopy(args, 1, minusCommand, 0, minusCommand.length); return new Command(args[0], parser.parse(commands.get(args[0]), minusCommand, commandWithArgs.get(args[0]))); } else { throw new ParseException(MessageFormat.format("invalid sub-command [{0}]", args[0])); } } } }
CLIParser { public Command parse(String[] args) throws ParseException { if (args.length == 0) { throw new ParseException("missing sub-command"); } else { if (commands.containsKey(args[0])) { GnuParser parser = new GnuParser(); String[] minusCommand = new String[args.length - 1]; System.arraycopy(args, 1, minusCommand, 0, minusCommand.length); return new Command(args[0], parser.parse(commands.get(args[0]), minusCommand, commandWithArgs.get(args[0]))); } else { throw new ParseException(MessageFormat.format("invalid sub-command [{0}]", args[0])); } } } CLIParser(String cliName, String[] cliHelp); }
CLIParser { public Command parse(String[] args) throws ParseException { if (args.length == 0) { throw new ParseException("missing sub-command"); } else { if (commands.containsKey(args[0])) { GnuParser parser = new GnuParser(); String[] minusCommand = new String[args.length - 1]; System.arraycopy(args, 1, minusCommand, 0, minusCommand.length); return new Command(args[0], parser.parse(commands.get(args[0]), minusCommand, commandWithArgs.get(args[0]))); } else { throw new ParseException(MessageFormat.format("invalid sub-command [{0}]", args[0])); } } } CLIParser(String cliName, String[] cliHelp); void addCommand(String command, String argsHelp, String commandHelp, Options commandOptions,
                           boolean hasArguments); Command parse(String[] args); String shortHelp(); void showHelp(); }
CLIParser { public Command parse(String[] args) throws ParseException { if (args.length == 0) { throw new ParseException("missing sub-command"); } else { if (commands.containsKey(args[0])) { GnuParser parser = new GnuParser(); String[] minusCommand = new String[args.length - 1]; System.arraycopy(args, 1, minusCommand, 0, minusCommand.length); return new Command(args[0], parser.parse(commands.get(args[0]), minusCommand, commandWithArgs.get(args[0]))); } else { throw new ParseException(MessageFormat.format("invalid sub-command [{0}]", args[0])); } } } CLIParser(String cliName, String[] cliHelp); void addCommand(String command, String argsHelp, String commandHelp, Options commandOptions,
                           boolean hasArguments); Command parse(String[] args); String shortHelp(); void showHelp();  }