@Test public void commandAliasExists() throws Exception { TestShell shell = new TestShell(); assertEquals(0, shell.run("cmdAlias")); String warningMsg = "WARNING: cmdAlias is not a stable CLI command. It may be removed in the" + " future. Use with caution in scripts. You may use 'cmd -O' instead."; String output = mOutput.toString(); assertTrue(String.format("Output should contain proper warning.\nActual: %s\nExpected: %s", output, warningMsg), output.contains(warningMsg)); }
public int run(String... argv) { if (argv.length == 0) { printUsage(); return -1; } String cmd = argv[0]; Command command = mCommands.get(cmd); if (command == null) { String[] replacementCmd = getReplacementCmd(cmd); if (replacementCmd == null) { System.err.println(String.format("%s is an unknown command.", cmd)); printUsage(); return -1; } else { if (mUnstableAlias != null && mUnstableAlias.contains(cmd)) { String deprecatedMsg = String.format("WARNING: %s is not a stable CLI command. It may be removed in the " + "future. Use with caution in scripts. You may use '%s' instead.", cmd, StringUtils.join(replacementCmd, " ")); System.out.println(deprecatedMsg); } String[] replacementArgv = (String[]) ArrayUtils.addAll(replacementCmd, ArrayUtils.subarray(argv, 1, argv.length)); return run(replacementArgv); } } CommandLine cmdline; try { String[] currArgs = Arrays.copyOf(argv, argv.length); while (command.hasSubCommand()) { if (currArgs.length < 2) { throw new InvalidArgumentException("No sub-command is specified"); } if (!command.getSubCommands().containsKey(currArgs[1])) { throw new InvalidArgumentException("Unknown sub-command: " + currArgs[1]); } command = command.getSubCommands().get(currArgs[1]); if (currArgs.length >= 2) { currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); } } currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); cmdline = command.parseAndValidateArgs(currArgs); } catch (InvalidArgumentException e) { System.out.println(e.getMessage()); System.out.println("Usage: " + command.getUsage()); System.out.println(command.getDescription()); LOG.error("Invalid arguments for command {}:", command.getCommandName(), e); return -1; } try { return command.run(cmdline); } catch (Exception e) { System.out.println(e.getMessage()); LOG.error("Error running " + StringUtils.join(argv, " "), e); return -1; } }
AbstractShell implements Closeable { public int run(String... argv) { if (argv.length == 0) { printUsage(); return -1; } String cmd = argv[0]; Command command = mCommands.get(cmd); if (command == null) { String[] replacementCmd = getReplacementCmd(cmd); if (replacementCmd == null) { System.err.println(String.format("%s is an unknown command.", cmd)); printUsage(); return -1; } else { if (mUnstableAlias != null && mUnstableAlias.contains(cmd)) { String deprecatedMsg = String.format("WARNING: %s is not a stable CLI command. It may be removed in the " + "future. Use with caution in scripts. You may use '%s' instead.", cmd, StringUtils.join(replacementCmd, " ")); System.out.println(deprecatedMsg); } String[] replacementArgv = (String[]) ArrayUtils.addAll(replacementCmd, ArrayUtils.subarray(argv, 1, argv.length)); return run(replacementArgv); } } CommandLine cmdline; try { String[] currArgs = Arrays.copyOf(argv, argv.length); while (command.hasSubCommand()) { if (currArgs.length < 2) { throw new InvalidArgumentException("No sub-command is specified"); } if (!command.getSubCommands().containsKey(currArgs[1])) { throw new InvalidArgumentException("Unknown sub-command: " + currArgs[1]); } command = command.getSubCommands().get(currArgs[1]); if (currArgs.length >= 2) { currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); } } currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); cmdline = command.parseAndValidateArgs(currArgs); } catch (InvalidArgumentException e) { System.out.println(e.getMessage()); System.out.println("Usage: " + command.getUsage()); System.out.println(command.getDescription()); LOG.error("Invalid arguments for command {}:", command.getCommandName(), e); return -1; } try { return command.run(cmdline); } catch (Exception e) { System.out.println(e.getMessage()); LOG.error("Error running " + StringUtils.join(argv, " "), e); return -1; } } }
AbstractShell implements Closeable { public int run(String... argv) { if (argv.length == 0) { printUsage(); return -1; } String cmd = argv[0]; Command command = mCommands.get(cmd); if (command == null) { String[] replacementCmd = getReplacementCmd(cmd); if (replacementCmd == null) { System.err.println(String.format("%s is an unknown command.", cmd)); printUsage(); return -1; } else { if (mUnstableAlias != null && mUnstableAlias.contains(cmd)) { String deprecatedMsg = String.format("WARNING: %s is not a stable CLI command. It may be removed in the " + "future. Use with caution in scripts. You may use '%s' instead.", cmd, StringUtils.join(replacementCmd, " ")); System.out.println(deprecatedMsg); } String[] replacementArgv = (String[]) ArrayUtils.addAll(replacementCmd, ArrayUtils.subarray(argv, 1, argv.length)); return run(replacementArgv); } } CommandLine cmdline; try { String[] currArgs = Arrays.copyOf(argv, argv.length); while (command.hasSubCommand()) { if (currArgs.length < 2) { throw new InvalidArgumentException("No sub-command is specified"); } if (!command.getSubCommands().containsKey(currArgs[1])) { throw new InvalidArgumentException("Unknown sub-command: " + currArgs[1]); } command = command.getSubCommands().get(currArgs[1]); if (currArgs.length >= 2) { currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); } } currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); cmdline = command.parseAndValidateArgs(currArgs); } catch (InvalidArgumentException e) { System.out.println(e.getMessage()); System.out.println("Usage: " + command.getUsage()); System.out.println(command.getDescription()); LOG.error("Invalid arguments for command {}:", command.getCommandName(), e); return -1; } try { return command.run(cmdline); } catch (Exception e) { System.out.println(e.getMessage()); LOG.error("Error running " + StringUtils.join(argv, " "), e); return -1; } } AbstractShell(Map<String, String[]> commandAlias,
      Set<String> unstableAlias, InstancedConfiguration conf); }
AbstractShell implements Closeable { public int run(String... argv) { if (argv.length == 0) { printUsage(); return -1; } String cmd = argv[0]; Command command = mCommands.get(cmd); if (command == null) { String[] replacementCmd = getReplacementCmd(cmd); if (replacementCmd == null) { System.err.println(String.format("%s is an unknown command.", cmd)); printUsage(); return -1; } else { if (mUnstableAlias != null && mUnstableAlias.contains(cmd)) { String deprecatedMsg = String.format("WARNING: %s is not a stable CLI command. It may be removed in the " + "future. Use with caution in scripts. You may use '%s' instead.", cmd, StringUtils.join(replacementCmd, " ")); System.out.println(deprecatedMsg); } String[] replacementArgv = (String[]) ArrayUtils.addAll(replacementCmd, ArrayUtils.subarray(argv, 1, argv.length)); return run(replacementArgv); } } CommandLine cmdline; try { String[] currArgs = Arrays.copyOf(argv, argv.length); while (command.hasSubCommand()) { if (currArgs.length < 2) { throw new InvalidArgumentException("No sub-command is specified"); } if (!command.getSubCommands().containsKey(currArgs[1])) { throw new InvalidArgumentException("Unknown sub-command: " + currArgs[1]); } command = command.getSubCommands().get(currArgs[1]); if (currArgs.length >= 2) { currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); } } currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); cmdline = command.parseAndValidateArgs(currArgs); } catch (InvalidArgumentException e) { System.out.println(e.getMessage()); System.out.println("Usage: " + command.getUsage()); System.out.println(command.getDescription()); LOG.error("Invalid arguments for command {}:", command.getCommandName(), e); return -1; } try { return command.run(cmdline); } catch (Exception e) { System.out.println(e.getMessage()); LOG.error("Error running " + StringUtils.join(argv, " "), e); return -1; } } AbstractShell(Map<String, String[]> commandAlias,
      Set<String> unstableAlias, InstancedConfiguration conf); int run(String... argv); Collection<Command> getCommands(); @Override void close(); }
AbstractShell implements Closeable { public int run(String... argv) { if (argv.length == 0) { printUsage(); return -1; } String cmd = argv[0]; Command command = mCommands.get(cmd); if (command == null) { String[] replacementCmd = getReplacementCmd(cmd); if (replacementCmd == null) { System.err.println(String.format("%s is an unknown command.", cmd)); printUsage(); return -1; } else { if (mUnstableAlias != null && mUnstableAlias.contains(cmd)) { String deprecatedMsg = String.format("WARNING: %s is not a stable CLI command. It may be removed in the " + "future. Use with caution in scripts. You may use '%s' instead.", cmd, StringUtils.join(replacementCmd, " ")); System.out.println(deprecatedMsg); } String[] replacementArgv = (String[]) ArrayUtils.addAll(replacementCmd, ArrayUtils.subarray(argv, 1, argv.length)); return run(replacementArgv); } } CommandLine cmdline; try { String[] currArgs = Arrays.copyOf(argv, argv.length); while (command.hasSubCommand()) { if (currArgs.length < 2) { throw new InvalidArgumentException("No sub-command is specified"); } if (!command.getSubCommands().containsKey(currArgs[1])) { throw new InvalidArgumentException("Unknown sub-command: " + currArgs[1]); } command = command.getSubCommands().get(currArgs[1]); if (currArgs.length >= 2) { currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); } } currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length); cmdline = command.parseAndValidateArgs(currArgs); } catch (InvalidArgumentException e) { System.out.println(e.getMessage()); System.out.println("Usage: " + command.getUsage()); System.out.println(command.getDescription()); LOG.error("Invalid arguments for command {}:", command.getCommandName(), e); return -1; } try { return command.run(cmdline); } catch (Exception e) { System.out.println(e.getMessage()); LOG.error("Error running " + StringUtils.join(argv, " "), e); return -1; } } AbstractShell(Map<String, String[]> commandAlias,
      Set<String> unstableAlias, InstancedConfiguration conf); int run(String... argv); Collection<Command> getCommands(); @Override void close();  }