CRecordCliHandle

This message is sent to registered console handlers when the user enters a registered command in the console. The message includes the command and any parameters entered. The response to this message should contain the text to be displayed on the console.

The message is part of the console API.

{
  "id": "d9c9e057-b172-40a5-8ae0-23d51e226321",
  "name": "CLI_HANDLE",
  "description": "Forward the command line to the command line manager.",
  "slots": [
    {
      "key": "1",
      "name": "COMMAND_LINE",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The command line."
    },
    {
      "key": "2",
      "name": "DISPLAY",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "TARGET_ADDRESS",
      "description": "The target address of the display."
    },
    {
      "key": "3",
      "name": "COMMAND",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The command."
    },
    {
      "key": "4",
      "name": "ARGUMENTS",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING_ARRAY",
      "description": "The arguments."
    },
    {
      "key": "10",
      "name": "IS_VALID_COMMAND",
      "direction": "ANSWER",
      "mandatory": "false",
      "type": "BOOLEAN",
      "description": "True if the command line is a valid command. The command will be added to the history buffer."
    },
    {
      "key": "11",
      "name": "OUTPUT",
      "direction": "ANSWER",
      "mandatory": "false",
      "type": "STRING",
      "description": "The output caused by the command."
    }
  ]
}

Arguments

  • COMMAND_LINE contains the user's input.
  • DISPLAY indicates the address of the display where the user made the input.
  • COMMAND is the instruction recognized by the interpreter.
  • ARGUMENTS are the tokens that were appended to the command.
  • IS_VALID_COMMAND is true if the input is recognized as a valid command.
  • OUTPUT indicates the text that should be displayed on the console as a response to the command.

Usage

Registration of the message handler for CRecordCliHandle:

addMessageHandler(CRecordCliHandle.ID,
                  this::asyncCliHandle);

Example implementation of the handler:

private boolean asyncCliHandle(@NotNull final CEnvelope aEnvelope,
                               @NotNull final CRecord aRecord) throws CException
{
    if (aEnvelope.isAnswer())
    {
        return false;
    }
    else
    {
        final String command = CRecordCliHandle.getCommand(aRecord,
                                                           "");
        if (QUIT.equals(command) || EXIT.equals(command))
        {
            final String[] args = CRecordCliHandle.getArguments(aRecord,
                                                                null);
            if (args != null && args.length >= 1 && args[0] != null)
            {
                int exitCode = CUtilInteger.fromObject(args[0],
                                                    0);
            }
            shutDown(exitCode);
        }
        aEnvelope.setResultSuccess();
        return true;
    }
}