Java 类org.springframework.boot.cli.command.Command 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CommandCompleter.java   
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);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CommandCompleter.java   
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
    int completionIndex = super.complete(buffer, cursor, candidates);
    int spaceIndex = buffer.indexOf(' ');
    String commandName = (spaceIndex == -1) ? "" : buffer.substring(0, spaceIndex);
    if (!"".equals(commandName.trim())) {
        for (Command command : this.commands) {
            if (command.getName().equals(commandName)) {
                if (cursor == buffer.length() && buffer.endsWith(" ")) {
                    printUsage(command);
                    break;
                }
                Completer completer = this.commandCompleters.get(command.getName());
                if (completer != null) {
                    completionIndex = completer.complete(buffer, cursor, candidates);
                    break;
                }
            }
        }
    }
    return completionIndex;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HelpCommand.java   
@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;
}
项目:spring-boot-concourse    文件:CommandCompleter.java   
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);
}
项目:spring-boot-concourse    文件:CommandCompleter.java   
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
    int completionIndex = super.complete(buffer, cursor, candidates);
    int spaceIndex = buffer.indexOf(' ');
    String commandName = (spaceIndex == -1) ? "" : buffer.substring(0, spaceIndex);
    if (!"".equals(commandName.trim())) {
        for (Command command : this.commands) {
            if (command.getName().equals(commandName)) {
                if (cursor == buffer.length() && buffer.endsWith(" ")) {
                    printUsage(command);
                    break;
                }
                Completer completer = this.commandCompleters.get(command.getName());
                if (completer != null) {
                    completionIndex = completer.complete(buffer, cursor, candidates);
                    break;
                }
            }
        }
    }
    return completionIndex;
}
项目:spring-boot-concourse    文件:HelpCommand.java   
@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;
}
项目:contestparser    文件:CommandCompleter.java   
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);
}
项目:contestparser    文件:CommandCompleter.java   
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
    int completionIndex = super.complete(buffer, cursor, candidates);
    int spaceIndex = buffer.indexOf(' ');
    String commandName = (spaceIndex == -1) ? "" : buffer.substring(0, spaceIndex);
    if (!"".equals(commandName.trim())) {
        for (Command command : this.commands) {
            if (command.getName().equals(commandName)) {
                if (cursor == buffer.length() && buffer.endsWith(" ")) {
                    printUsage(command);
                    break;
                }
                Completer completer = this.commandCompleters.get(command.getName());
                if (completer != null) {
                    completionIndex = completer.complete(buffer, cursor, candidates);
                    break;
                }
            }
        }
    }
    return completionIndex;
}
项目:contestparser    文件:HelpCommand.java   
@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;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Shell.java   
private Iterable<Command> getCommands() {
    List<Command> commands = new ArrayList<Command>();
    ServiceLoader<CommandFactory> factories = ServiceLoader.load(CommandFactory.class,
            getClass().getClassLoader());
    for (CommandFactory factory : factories) {
        for (Command command : factory.getCommands()) {
            commands.add(convertToForkCommand(command));
        }
    }
    commands.add(new PromptCommand(this.prompts));
    commands.add(new ClearCommand(this.consoleReader));
    commands.add(new ExitCommand());
    return commands;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Shell.java   
private Command convertToForkCommand(Command command) {
    for (Class<?> nonForked : NON_FORKED_COMMANDS) {
        if (nonForked.isInstance(command)) {
            return command;
        }
    }
    return new ForkProcessCommand(command);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Shell.java   
@Override
public Command findCommand(String name) {
    if (name.startsWith("!")) {
        return new RunProcessCommand(name.substring(1));
    }
    if (this.aliases.containsKey(name)) {
        name = this.aliases.get(name);
    }
    return super.findCommand(name);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Shell.java   
public boolean handleSigInt() {
    Command command = this.lastCommand;
    if (command != null && command instanceof RunProcessCommand) {
        return ((RunProcessCommand) command).handleSigInt();
    }
    return false;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HintCommand.java   
private void showCommandHints(String starting) {
    for (Command command : this.commandRunner) {
        if (isHintMatch(command, starting)) {
            Log.info(command.getName() + " " + command.getDescription());
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HintCommand.java   
private boolean isHintMatch(Command command, String starting) {
    if (command instanceof HintCommand) {
        return false;
    }
    return command.getName().startsWith(starting)
            || (this.commandRunner.isOptionCommand(command)
                    && ("--" + command.getName()).startsWith(starting));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HintCommand.java   
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());
                    }
                }
            }
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HelpCommand.java   
@Override
public ExitStatus run(String... args) throws Exception {
    if (args.length == 0) {
        throw new NoHelpCommandArgumentsException();
    }
    String commandName = args[0];
    for (Command command : this.commandRunner) {
        if (command.getName().equals(commandName)) {
            Log.info(this.commandRunner.getName() + command.getName() + " - "
                    + command.getDescription());
            Log.info("");
            if (command.getUsageHelp() != null) {
                Log.info("usage: " + this.commandRunner.getName() + command.getName()
                        + " " + command.getUsageHelp());
                Log.info("");
            }
            if (command.getHelp() != null) {
                Log.info(command.getHelp());
            }
            Collection<HelpExample> examples = command.getExamples();
            if (examples != null) {
                Log.info(examples.size() == 1 ? "example:" : "examples:");
                Log.info("");
                for (HelpExample example : examples) {
                    Log.info("    " + example.getDescription() + ":");
                    Log.info("        $ " + example.getExample());
                    Log.info("");
                }
                Log.info("");
            }
            return ExitStatus.OK;
        }
    }
    throw new NoSuchCommandException(commandName);
}
项目:spring-boot-concourse    文件:Shell.java   
private Iterable<Command> getCommands() {
    List<Command> commands = new ArrayList<Command>();
    ServiceLoader<CommandFactory> factories = ServiceLoader.load(CommandFactory.class,
            getClass().getClassLoader());
    for (CommandFactory factory : factories) {
        for (Command command : factory.getCommands()) {
            commands.add(convertToForkCommand(command));
        }
    }
    commands.add(new PromptCommand(this.prompts));
    commands.add(new ClearCommand(this.consoleReader));
    commands.add(new ExitCommand());
    return commands;
}
项目:spring-boot-concourse    文件:Shell.java   
private Command convertToForkCommand(Command command) {
    for (Class<?> nonForked : NON_FORKED_COMMANDS) {
        if (nonForked.isInstance(command)) {
            return command;
        }
    }
    return new ForkProcessCommand(command);
}
项目:spring-boot-concourse    文件:Shell.java   
@Override
public Command findCommand(String name) {
    if (name.startsWith("!")) {
        return new RunProcessCommand(name.substring(1));
    }
    if (this.aliases.containsKey(name)) {
        name = this.aliases.get(name);
    }
    return super.findCommand(name);
}
项目:spring-boot-concourse    文件:Shell.java   
public boolean handleSigInt() {
    Command command = this.lastCommand;
    if (command != null && command instanceof RunProcessCommand) {
        return ((RunProcessCommand) command).handleSigInt();
    }
    return false;
}
项目:spring-boot-concourse    文件:HintCommand.java   
private void showCommandHints(String starting) {
    for (Command command : this.commandRunner) {
        if (isHintMatch(command, starting)) {
            Log.info(command.getName() + " " + command.getDescription());
        }
    }
}
项目:spring-boot-concourse    文件:HintCommand.java   
private boolean isHintMatch(Command command, String starting) {
    if (command instanceof HintCommand) {
        return false;
    }
    return command.getName().startsWith(starting)
            || (this.commandRunner.isOptionCommand(command)
                    && ("--" + command.getName()).startsWith(starting));
}
项目:spring-boot-concourse    文件:HintCommand.java   
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());
                    }
                }
            }
        }
    }
}
项目:spring-boot-concourse    文件:HelpCommand.java   
@Override
public ExitStatus run(String... args) throws Exception {
    if (args.length == 0) {
        throw new NoHelpCommandArgumentsException();
    }
    String commandName = args[0];
    for (Command command : this.commandRunner) {
        if (command.getName().equals(commandName)) {
            Log.info(this.commandRunner.getName() + command.getName() + " - "
                    + command.getDescription());
            Log.info("");
            if (command.getUsageHelp() != null) {
                Log.info("usage: " + this.commandRunner.getName() + command.getName()
                        + " " + command.getUsageHelp());
                Log.info("");
            }
            if (command.getHelp() != null) {
                Log.info(command.getHelp());
            }
            Collection<HelpExample> examples = command.getExamples();
            if (examples != null) {
                Log.info(examples.size() == 1 ? "example:" : "examples:");
                Log.info("");
                for (HelpExample example : examples) {
                    Log.info("    " + example.getDescription() + ":");
                    Log.info("        $ " + example.getExample());
                    Log.info("");
                }
                Log.info("");
            }
            return ExitStatus.OK;
        }
    }
    throw new NoSuchCommandException(commandName);
}
项目:contestparser    文件:Shell.java   
private Iterable<Command> getCommands() {
    List<Command> commands = new ArrayList<Command>();
    ServiceLoader<CommandFactory> factories = ServiceLoader.load(CommandFactory.class,
            getClass().getClassLoader());
    for (CommandFactory factory : factories) {
        for (Command command : factory.getCommands()) {
            commands.add(convertToForkCommand(command));
        }
    }
    commands.add(new PromptCommand(this.prompts));
    commands.add(new ClearCommand(this.consoleReader));
    commands.add(new ExitCommand());
    return commands;
}
项目:contestparser    文件:Shell.java   
private Command convertToForkCommand(Command command) {
    for (Class<?> nonForked : NON_FORKED_COMMANDS) {
        if (nonForked.isInstance(command)) {
            return command;
        }
    }
    return new ForkProcessCommand(command);
}
项目:contestparser    文件:Shell.java   
@Override
public Command findCommand(String name) {
    if (name.startsWith("!")) {
        return new RunProcessCommand(name.substring(1));
    }
    if (this.aliases.containsKey(name)) {
        name = this.aliases.get(name);
    }
    return super.findCommand(name);
}
项目:contestparser    文件:Shell.java   
public boolean handleSigInt() {
    Command command = this.lastCommand;
    if (command != null && command instanceof RunProcessCommand) {
        return ((RunProcessCommand) command).handleSigInt();
    }
    return false;
}
项目:contestparser    文件:HintCommand.java   
private void showCommandHints(String starting) {
    for (Command command : this.commandRunner) {
        if (isHintMatch(command, starting)) {
            Log.info(command.getName() + " " + command.getDescription());
        }
    }
}
项目:contestparser    文件:HintCommand.java   
private boolean isHintMatch(Command command, String starting) {
    if (command instanceof HintCommand) {
        return false;
    }
    return command.getName().startsWith(starting)
            || (this.commandRunner.isOptionCommand(command)
                    && ("--" + command.getName()).startsWith(starting));
}
项目:contestparser    文件:HintCommand.java   
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());
                    }
                }
            }
        }
    }
}
项目:contestparser    文件:HelpCommand.java   
@Override
public ExitStatus run(String... args) throws Exception {
    if (args.length == 0) {
        throw new NoHelpCommandArgumentsException();
    }
    String commandName = args[0];
    for (Command command : this.commandRunner) {
        if (command.getName().equals(commandName)) {
            Log.info(this.commandRunner.getName() + command.getName() + " - "
                    + command.getDescription());
            Log.info("");
            if (command.getUsageHelp() != null) {
                Log.info("usage: " + this.commandRunner.getName() + command.getName()
                        + " " + command.getUsageHelp());
                Log.info("");
            }
            if (command.getHelp() != null) {
                Log.info(command.getHelp());
            }
            Collection<HelpExample> examples = command.getExamples();
            if (examples != null) {
                Log.info(examples.size() == 1 ? "example:" : "examples:");
                Log.info("");
                for (HelpExample example : examples) {
                    Log.info("    " + example.getDescription() + ":");
                    Log.info("        $ " + example.getExample());
                    Log.info("");
                }
                Log.info("");
            }
            return ExitStatus.OK;
        }
    }
    throw new NoSuchCommandException(commandName);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:DefaultCommandFactory.java   
@Override
public Collection<Command> getCommands() {
    return DEFAULT_COMMANDS;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ForkProcessCommand.java   
ForkProcessCommand(Command command) {
    super(new JavaExecutable().toString());
    this.command = command;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Shell.java   
@Override
protected void beforeRun(Command command) {
    this.lastCommand = command;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Shell.java   
@Override
protected void afterRun(Command command) {
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HelpCommand.java   
private boolean isHelpShown(Command command) {
    if (command instanceof HelpCommand || command instanceof HintCommand) {
        return false;
    }
    return true;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CustomCommandFactory.java   
@Override
public Collection<Command> getCommands() {
    return Collections.<Command>singleton(new CustomCommand());
}
项目:spring-boot-concourse    文件:DefaultCommandFactory.java   
@Override
public Collection<Command> getCommands() {
    return DEFAULT_COMMANDS;
}