Search in sources :

Example 1 with NoHelpCommandArgumentsException

use of org.springframework.boot.cli.command.NoHelpCommandArgumentsException in project spring-boot by spring-projects.

the class HelpCommand method run.

@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);
}
Also used : Command(org.springframework.boot.cli.command.Command) AbstractCommand(org.springframework.boot.cli.command.AbstractCommand) HelpExample(org.springframework.boot.cli.command.HelpExample) NoSuchCommandException(org.springframework.boot.cli.command.NoSuchCommandException) NoHelpCommandArgumentsException(org.springframework.boot.cli.command.NoHelpCommandArgumentsException)

Aggregations

AbstractCommand (org.springframework.boot.cli.command.AbstractCommand)1 Command (org.springframework.boot.cli.command.Command)1 HelpExample (org.springframework.boot.cli.command.HelpExample)1 NoHelpCommandArgumentsException (org.springframework.boot.cli.command.NoHelpCommandArgumentsException)1 NoSuchCommandException (org.springframework.boot.cli.command.NoSuchCommandException)1