public CommandCompleter(ConsoleReader consoleReader, ArgumentDelimiter argumentDelimiter, Iterable<Command> commands) { this.console = consoleReader; List<String> names = new ArrayList<String>(); for (Command command : commands) { this.commands.add(command); names.add(command.getName()); List<String> options = new ArrayList<String>(); for (OptionHelp optionHelp : command.getOptionsHelp()) { options.addAll(optionHelp.getOptions()); } AggregateCompleter argumentCompleters = new AggregateCompleter( new StringsCompleter(options), new FileNameCompleter()); ArgumentCompleter argumentCompleter = new ArgumentCompleter(argumentDelimiter, argumentCompleters); argumentCompleter.setStrict(false); this.commandCompleters.put(command.getName(), argumentCompleter); } getStrings().addAll(names); }
@Override public Collection<OptionHelp> getOptionsHelp() { List<OptionHelp> help = new ArrayList<OptionHelp>(); for (final Command command : this.commandRunner) { if (isHelpShown(command)) { help.add(new OptionHelp() { @Override public Set<String> getOptions() { return Collections.singleton(command.getName()); } @Override public String getUsageHelp() { return command.getDescription(); } }); } } return help; }
public CommandCompleter(ConsoleReader consoleReader, ArgumentDelimiter argumentDelimiter, Iterable<Command> commands) { this.console = consoleReader; List<String> names = new ArrayList<String>(); for (Command command : commands) { this.commands.add(command); names.add(command.getName()); List<String> options = new ArrayList<String>(); for (OptionHelp optionHelp : command.getOptionsHelp()) { options.addAll(optionHelp.getOptions()); } AggregateCompleter arguementCompleters = new AggregateCompleter( new StringsCompleter(options), new FileNameCompleter()); ArgumentCompleter argumentCompleter = new ArgumentCompleter(argumentDelimiter, arguementCompleters); argumentCompleter.setStrict(false); this.commandCompleters.put(command.getName(), argumentCompleter); } getStrings().addAll(names); }
OptionHelpLine(OptionHelp optionHelp) { StringBuilder options = new StringBuilder(); for (String option : optionHelp.getOptions()) { options.append(options.length() == 0 ? "" : ", "); options.append(option); } this.options = options.toString(); this.usage = optionHelp.getUsageHelp(); }
private void showCommandOptionHints(String commandName, List<String> specifiedArguments, String starting) { Command command = this.commandRunner.findCommand(commandName); if (command != null) { for (OptionHelp help : command.getOptionsHelp()) { if (!alreadyUsed(help, specifiedArguments)) { for (String option : help.getOptions()) { if (option.startsWith(starting)) { Log.info(option + " " + help.getUsageHelp()); } } } } } }
private boolean alreadyUsed(OptionHelp help, List<String> specifiedArguments) { for (String argument : specifiedArguments) { if (help.getOptions().contains(argument)) { return true; } } return false; }
OptionHelpLine(OptionHelp optionHelp) { StringBuffer options = new StringBuffer(); for (String option : optionHelp.getOptions()) { options.append(options.length() == 0 ? "" : ", "); options.append(option); } this.options = options.toString(); this.usage = optionHelp.getUsageHelp(); }
@Override public Collection<OptionHelp> getOptionsHelp() { return Collections.emptyList(); }
@Override public Collection<OptionHelp> getOptionsHelp() { return this.handler.getOptionsHelp(); }
@Override public Collection<OptionHelp> getOptionsHelp() { return this.command.getOptionsHelp(); }
/** * Returns help for each supported option. * @return help for each of the command's options */ Collection<OptionHelp> getOptionsHelp();