Command mode

From Cloudrexx Development Wiki
Jump to: navigation, search

Cloudrexx command mode is a special mode Cloudrexx can run in. This mode allows to execute one command per request, which is useful for command-line or API-like cases.

Trigger

The command mode is automatically triggered in the following cases:

  • Cloudrexx is executed from command-line.
  • The request starts with the offset defined in \Cx\Core\Core\Controller\Cx::FOLDER_NAME_COMMAND_MODE ("/api" by default).

Usage

Command-line

Cloudrexx comes with a helper script "./cx" which starts Cloudrexx in command mode. Alternatively you may use "php index.php" to start Cloudrexx in command mode.

The synopsis is as follows:

./cx <command>[ <argumentList>]

HTTP

The synopsis is as follows:

/api/<command>[<argumentList]

Commands

Commands for command mode can be registered by components. Each command has a permission. If the requested command is not found or not accessible, the built-in "help" command is executed.

"help" command

This command lists all available commands (while respecting permissions) and a short or detailed description.

"v1" command

This command provides a RESTful API.

"Data" command

This command allows access to MediaSources. JSON Adapters are available as ./cx Data Json <adapterName> <method>[ <arguments>] or /api/Data/Json/<adapterName>/<method>[<arguments>]

Arguments

Command mode knows three different kinds of arguments:

  • Simple arguments: This is a string with no spaces
  • Key/value pairs: Key and value are separated by "="
  • A single data argument

Command-line

echo "Data" | ./cx MyCommand SimpleArgument Key=Value

The above example shows an example using all three kinds of arguments:

  • A simple argument named "SimpleArgument"
  • A Key/value pair named "Key" with the value "Value"
  • The data argument containing "Data"

HTTP

/api/MyCommand/SimpleArgument?Key=Value

The above example shows an example using two kinds of arguments:

  • A simple argument named "SimpleArgument"
  • A Key/value pair named "Key" with the value "Value"

The data argument is the POST data sent with the request if the request is a POST request.