Interface CommandHandler

    • Method Detail

      • isAvailable

        boolean isAvailable​(CommandContext ctx)
        Checks whether the command is available in the current context (e.g. some commands require connection with the controller, some are available only in the batch mode, etc)
        Parameters:
        ctx - current context
        Returns:
        true if the command can be executed in the current context, false - otherwise.
      • isBatchMode

        boolean isBatchMode​(CommandContext ctx)
        Whether the command supports batch mode or not. The result could depend on the context, e.g. it won't make sense to add 'some_command --help' to a batch.
        Parameters:
        ctx - the current context
        Returns:
        true if the command can be added to the batch, otherwise - false.
      • handle

        void handle​(CommandContext ctx)
             throws CommandLineException
        Executes the command.
        Parameters:
        ctx - current command context
        Throws:
        CommandLineException - if for any reason the command can't be properly handled the implementation must throw an instance of CommandLineException.
      • getArgument

        CommandArgument getArgument​(CommandContext ctx,
                                    String name)
        Returns command argument declared by the command handler corresponding to the argument name. Or null if the argument wasn't found among the accepted arguments.
        Parameters:
        ctx - the current context
        name - the name of the argument
        Returns:
        command argument corresponding to the argument name or null if the argument name wasn't recognized.
      • hasArgument

        boolean hasArgument​(CommandContext ctx,
                            String name)
        Checks whether the command handler recognizes the argument by the name.
        Parameters:
        ctx - the current context
        name - argument name to check
        Returns:
        true if the handler recognizes the argument, otherwise - false.
      • hasArgument

        boolean hasArgument​(CommandContext ctx,
                            int index)
        Checks whether the command handler accepts an argument with the specified index.
        Parameters:
        ctx - the current context
        index - argument index to check
        Returns:
        true if the handler accepts an argument with the specified index, otherwise - false.
      • getArguments

        Collection<CommandArgument> getArguments​(CommandContext ctx)
        Returns a collection of the command arguments the handler supports in the current context.
        Parameters:
        ctx - current command line context
        Returns:
        list of the command arguments supported in the current context