Refactor CLI internals for REPL shell

Numerous updates to the Spring CLI, primarily for better embedded REPL
shell support:

* Refactor the CLI application to help separate concerts between the
  main CLI and the embedded shell. Both the CLI and embedded shell now
  delegate to a new `CommandRunner` to handle running commands. The
  runner can be configured differently depending depending on need.
  For example, the embedded shell adds the 'prompt' and 'clear'
  commands.

* Most `Command` implementations have been moved to sub-packages so that
  they can be co-located with the classes that they use.

* Option commands are now only used in the CLI, the embedded shell
  does not user them and details have been removed from the Command
  interface.

* The REPL shell has been significantly refactored to:
    - Support CTRL-C to cancel the running process. This is supported
      when running external commands and most internal commands.
    - Fork a new JVM when running commands (primarily for CTRL-C support
      but also for potential memory and classpath issues)
    - Change the "continue" trigger from `<<` to `\`
    - Support command completion of files
    - Add ANSI color output
    - Provide 'help' support for internal commands (such as 'clear')
    - Remove the now redundant `stop` command

Fixes gh-227
This commit is contained in:
Phillip Webb
2014-01-14 15:06:03 -08:00
parent cad9fbfdf0
commit c8a1d8830c
48 changed files with 1693 additions and 922 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,9 +19,8 @@ package cli.command;
import java.util.Collection;
import java.util.Collections;
import org.springframework.boot.cli.Command;
import org.springframework.boot.cli.CommandFactory;
import org.springframework.boot.cli.SpringCli;
import org.springframework.boot.cli.command.Command;
import org.springframework.boot.cli.command.CommandFactory;
/**
* @author Dave Syer
@@ -29,7 +28,7 @@ import org.springframework.boot.cli.SpringCli;
public class CustomCommandFactory implements CommandFactory {
@Override
public Collection<Command> getCommands(SpringCli cli) {
public Collection<Command> getCommands() {
return Collections.<Command> singleton(new CustomCommand());
}