Class DefaultCommandExecutor

java.lang.Object
com.codingchili.core.context.DefaultCommandExecutor
All Implemented Interfaces:
CommandExecutor
Direct Known Subclasses:
LauncherCommandExecutor

public class DefaultCommandExecutor extends Object implements CommandExecutor
Parses and executes commands from the command line.
  • Field Details

  • Constructor Details

    • DefaultCommandExecutor

      public DefaultCommandExecutor()
      uses a ConsoleLogger as default.
    • DefaultCommandExecutor

      public DefaultCommandExecutor(Logger logger)
      Parameters:
      logger - to write output to.
  • Method Details

    • execute

      public CommandExecutor execute(io.vertx.core.Promise<CommandResult> future, String... commandLine)
      Description copied from interface: CommandExecutor
      Executes the given command. Sets handled to false if the command does not exist.
      Specified by:
      execute in interface CommandExecutor
      Parameters:
      future - callback: true if startup should be aborted.
      commandLine - the commands/properties to execute.
      Returns:
      fluent
    • execute

      public CommandResult execute(String... command)
      Description copied from interface: CommandExecutor
      Executes the given command synchronously.
      Specified by:
      execute in interface CommandExecutor
      Parameters:
      command - the command to execute
      Returns:
      true if startup is to be aborted.
    • getCommand

      public Optional<String> getCommand()
      Description copied from interface: CommandExecutor
      Get the first command passed to the executor.
      Specified by:
      getCommand in interface CommandExecutor
      Returns:
      the initial command as a string.
    • getParser

      public CommandParser getParser()
    • addProperty

      public CommandExecutor addProperty(String key, String value)
      Description copied from interface: CommandExecutor
      Adds a new property to the CommandExecutor that is passed to executed commands.
      Specified by:
      addProperty in interface CommandExecutor
      Parameters:
      key - the key to identify the property by
      value - a value to bind to the property key
      Returns:
      fluent
    • hasProperty

      public boolean hasProperty(String name)
      Description copied from interface: CommandExecutor
      Check if a property has been set from the commandline.
      Specified by:
      hasProperty in interface CommandExecutor
      Parameters:
      name - the name of the property
      Returns:
      true if the property exists
    • getProperty

      public Optional<String> getProperty(String name)
      Description copied from interface: CommandExecutor
      Get a commandline property passed to the Executor.
      Specified by:
      getProperty in interface CommandExecutor
      Parameters:
      name - the name of the property to get
      Returns:
      the property as a string value
    • getAllProperties

      public List<String> getAllProperties(String name)
      Description copied from interface: CommandExecutor
      Get a commandline property passed to the Executor.
      Specified by:
      getAllProperties in interface CommandExecutor
      Parameters:
      name - the name of the property to get
      Returns:
      a list of all the property values.
    • add

      public CommandExecutor add(Command command)
      Description copied from interface: CommandExecutor
      Registers a new command to the CommandExecutor.
      Specified by:
      add in interface CommandExecutor
      Parameters:
      command - the command to add
      Returns:
      fluent
    • add

      public CommandExecutor add(BiFunction<io.vertx.core.Promise<CommandResult>,​CommandExecutor,​Void> executor, String name, String description)
      Description copied from interface: CommandExecutor
      Adds a new asynchronous command using the default implementation.
      Specified by:
      add in interface CommandExecutor
      Parameters:
      executor - the method to execute when the command is executed.
      name - the name of the command to add
      description - the description of the command
      Returns:
      fluent
    • add

      public CommandExecutor add(Function<CommandExecutor,​CommandResult> executor, String name, String description)
      Description copied from interface: CommandExecutor
      Adds a new synchronous command using the default implementation.
      Specified by:
      add in interface CommandExecutor
      Parameters:
      executor - the method to execute when the command is executed
      name - the name of the command to add
      description - the description of the command
      Returns:
      fluent
    • list

      public Collection<Command> list()
      Description copied from interface: CommandExecutor
      Lists all commands added to the executor.
      Specified by:
      list in interface CommandExecutor
      Returns:
      a list of commands registered.
    • clear

      public CommandExecutor clear()
      Description copied from interface: CommandExecutor
      Removes all registered commands.
      Specified by:
      clear in interface CommandExecutor
      Returns:
      fluent.