# Command Line Interface

This module includes functions that control the Thread stack's execution.

## Summary

| ### Typedefs ||
|---|---|
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga799acf587aa7d73ba1d996062c5a6620` | typedef `struct https://openthread.io/reference/struct/ot-cli-command` Represents a user provided CLI command entry. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga7c9dd986fe2d556b84ffe365f27abe3b` | typedef `struct https://openthread.io/reference/struct/ot-cli-interpreter` Opaque type for a CLI interpreter. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga84b4cb79bf8b1e48b60d6b68afe3be68)(void *aContext, const char *aFormat, va_list aArguments)` | typedef `int(*` Pointer is called to notify about CLI interpreter output. |

| ### Functions ||
|---|---|
| `https://openthread.io/reference/group/api-cli#group__api-cli_1gaca493e431d8013359044b27da076c7d0(https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49 aError)` | `void` Write a given error code as the result of previous command to the static CLI interpreter output. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga6f291e844060eec2e96cfb010f53d496(void)` | `https://openthread.io/reference/struct/ot-cli-interpreter *` Gets the pointer to the static CLI interpreter. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga94273eb04a7c8942c0d2c5e97effd4aa(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-cli#group__api-cli_1ga84b4cb79bf8b1e48b60d6b68afe3be68 aCallback, void *aContext)` | `void` Initialize the static CLI interpreter. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga4f6a74b31893bc38d78b4c7b6f8c23a5(char *aLine)` | `void` Feeds input to the static CLI interpreter. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga08fac06bce9067c1b2b6a1e598891413(https://openthread.io/reference/struct/ot-cli-interpreter *aInterpreter)` | `void` Finalizes the CLI interpreter. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga31af54d4f13efdd09e7132b371024458(void)` | `size_t` Gets the size of the CLI interpreter object. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga218b09e3c76d74a4cfb00042f59e8e53(void *aBuffer, size_t aSize, https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-cli#group__api-cli_1ga84b4cb79bf8b1e48b60d6b68afe3be68 aCallback, void *aContext)` | `https://openthread.io/reference/struct/ot-cli-interpreter *` Initializes a CLI interpreter. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1gaaf2faa1131db26fd6366c1671ff92777(https://openthread.io/reference/struct/ot-cli-interpreter *aInterpreter, char *aLine)` | `void` Feeds input to the CLI interpreter. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga2c8bed0dcbaf50fb16e97e8517b5e5c3(https://openthread.io/reference/struct/ot-cli-interpreter *aInterpreter, bool aEnable)` | `void` Configures whether or not the CLI interpreter outputs the prompt string. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga56c4e7cafc2b7764111f128fa9468de6(const uint8_t *aBytes, uint8_t aLength)` | `void` Write a number of bytes to the static CLI interpreter output as a hex string. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1gaca847cb0fb47510381b4f844a551b706(const char *aFmt, ...)` | `void` Write formatted string to the static CLI interpreter output. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1gac0bb479ea1529c98a2fc9b8400ca9998(https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga6ac756046db5c24c6c068139b689dbdb aLogLevel, https://openthread.io/reference/group/plat-logging#group__plat-logging_1gaee25d56d067df60b93f75b2ff587668c aLogRegion, const char *aFormat, va_list aArgs)` | `void` Callback to write the OpenThread Log to the static CLI interpreter output. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga7bab8e12ab405ce34204b018a9632eae(const https://openthread.io/reference/struct/ot-cli-command *aUserCommands, uint8_t aLength, void *aContext)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Set a user command table on the static CLI interpreter. |
| `https://openthread.io/reference/group/api-cli#group__api-cli_1ga0d732e43225a57dd7d25b2403c1cfae9(void)` | `void` Callback to allow vendor specific commands to be added to the user command table. |

| ### Structs ||
|---|---|
| [otCliCommand](https://openthread.io/reference/struct/ot-cli-command) | Represents a user provided CLI command entry. |

## Typedefs

### otCliCommand

```
struct otCliCommand otCliCommand
```
Represents a user provided CLI command entry.

### otCliInterpreter

```
struct otCliInterpreter otCliInterpreter
```
Opaque type for a CLI interpreter.

### otCliOutputCallback

```
int(* otCliOutputCallback)(void *aContext, const char *aFormat, va_list aArguments)
```
Pointer is called to notify about CLI interpreter output.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[out] aContext` | A user context pointer. | | `[in] aFormat` | The format string. | | `[in] aArguments` | The format string arguments. | |
| **Returns** | Number of bytes written by the callback. |

## Functions

### otCliAppendResult

```
void otCliAppendResult(
  otError aError
)
```
Write a given error code as the result of previous command to the static CLI interpreter output.

Requires `OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE`.

This is intended for use by user-provided CLI command handlers.

If the `aError` is `OT_ERROR_PENDING` nothing will be outputted.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aError` | Error code value. | |

### otCliGetStaticInterpreter

```
otCliInterpreter * otCliGetStaticInterpreter(
  void
)
```
Gets the pointer to the static CLI interpreter.

Requires `OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE`.

<br />

| Details ||
|---|---|
| **Returns** | A pointer to the static CLI interpreter. |

### otCliInit

```
void otCliInit(
  otInstance *aInstance,
  otCliOutputCallback aCallback,
  void *aContext
)
```
Initialize the static CLI interpreter.

Requires `OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | The OpenThread instance structure. | | `[in] aCallback` | A callback method called to process CLI output. | | `[in] aContext` | A user context pointer. | |

### otCliInputLine

```
void otCliInputLine(
  char *aLine
)
```
Feeds input to the static CLI interpreter.

Requires `OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aLine` | A pointer to a null-terminated string. | |

### otCliInterpreterFinalize

```
void otCliInterpreterFinalize(
  otCliInterpreter *aInterpreter
)
```
Finalizes the CLI interpreter.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInterpreter` | A pointer to a CLI interpreter. | |

### otCliInterpreterGetSize

```
size_t otCliInterpreterGetSize(
  void
)
```
Gets the size of the CLI interpreter object.

<br />

| Details ||
|---|---|
| **Returns** | The size of the CLI interpreter object in bytes. |

### otCliInterpreterInit

```
otCliInterpreter * otCliInterpreterInit(
  void *aBuffer,
  size_t aSize,
  otInstance *aInstance,
  otCliOutputCallback aCallback,
  void *aContext
)
```
Initializes a CLI interpreter.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aBuffer` | A pointer to a memory buffer for the CLI interpreter. | | `[in] aSize` | The size of the memory buffer. | | `[in] aInstance` | The OpenThread instance structure. | | `[in] aCallback` | A callback method called to process CLI output. | | `[in] aContext` | A user context pointer. | |
| **Returns** | A pointer to the initialized CLI interpreter, or `NULL` if `aSize` is too small. |

### otCliInterpreterInputLine

```
void otCliInterpreterInputLine(
  otCliInterpreter *aInterpreter,
  char *aLine
)
```
Feeds input to the CLI interpreter.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInterpreter` | A pointer to a CLI interpreter. | | `[in] aLine` | A pointer to a null-terminated string. | |

### otCliInterpreterSetPromptConfig

```
void otCliInterpreterSetPromptConfig(
  otCliInterpreter *aInterpreter,
  bool aEnable
)
```
Configures whether or not the CLI interpreter outputs the prompt string.

Requires `OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE`.

It is enabled by default.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInterpreter` | A pointer to a CLI interpreter. | | `[in] aEnable` | TRUE to enable outputting the prompt, FALSE to disable. | |

### otCliOutputBytes

```
void otCliOutputBytes(
  const uint8_t *aBytes,
  uint8_t aLength
)
```
Write a number of bytes to the static CLI interpreter output as a hex string.

Requires `OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE`.

This is intended for use by user-provided CLI command handlers.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aBytes` | A pointer to data which should be printed. | | `[in] aLength` | `aBytes` length. | |

### otCliOutputFormat

```
void otCliOutputFormat(
  const char *aFmt,
  ...
)
```
Write formatted string to the static CLI interpreter output.

Requires `OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE`.

This is intended for use by user-provided CLI command handlers.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aFmt` | A pointer to the format string. | | `[in] ...` | A matching list of arguments. | |

### otCliPlatLogv

```
void otCliPlatLogv(
  otLogLevel aLogLevel,
  otLogRegion aLogRegion,
  const char *aFormat,
  va_list aArgs
)
```
Callback to write the OpenThread Log to the static CLI interpreter output.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aLogLevel` | The log level. | | `[in] aLogRegion` | The log region. | | `[in] aFormat` | A pointer to the format string. | | `[in] aArgs` | va_list matching aFormat. | |

### otCliSetUserCommands

```
otError otCliSetUserCommands(
  const otCliCommand *aUserCommands,
  uint8_t aLength,
  void *aContext
)
```
Set a user command table on the static CLI interpreter.

Requires `OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aUserCommands` | A pointer to an array with user commands. | | `[in] aLength` | The `aUserCommands` length. | | `[in] aContext` | The context passed to the handler. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully updated command table with commands from `aUserCommands`. | | `OT_ERROR_NO_BUFS` | Maximum number of command entries have already been set. | |

### otCliVendorSetUserCommands

```
void otCliVendorSetUserCommands(
  void
)
```
Callback to allow vendor specific commands to be added to the user command table.

Available when `OPENTHREAD_CONFIG_CLI_VENDOR_COMMANDS_ENABLE` is enabled and `OPENTHREAD_CONFIG_CLI_MAX_USER_CMD_ENTRIES` is greater than 1.

Requires `OPENTHREAD_CONFIG_CLI_STATIC_INTERPRETER_ENABLE`.

## Resources

OpenThread API Reference topics originate from the source code, available
on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread).
For more information, or to contribute to our documentation, refer to
[Resources](https://openthread.io/resources).