Copy as Markdown[View as Markdown](/docs/cli/cli-commands.md)

***

# Commands CLI Commands

Manage commands in your EventCatalog from the command line.

## getCommand[​](#getcommand "Direct link to getCommand")

Returns a command from EventCatalog by its ID

**Arguments:**

| Name    | Type   | Required | Description                                    |
| ------- | ------ | -------- | ---------------------------------------------- |
| id      | string | Yes      | The ID of the command to retrieve              |
| version | string | No       | Specific version to retrieve (supports semver) |

**Examples:**

```
# Get the latest command
npx @eventcatalog/cli getCommand "CreateOrder"

# Get a specific version
npx @eventcatalog/cli getCommand "CreateOrder" "1.0.0"
```

***

## getCommands[​](#getcommands "Direct link to getCommands")

Returns all commands from EventCatalog

**Arguments:**

| Name    | Type | Required | Description                           |
| ------- | ---- | -------- | ------------------------------------- |
| options | json | No       | Options: {latestOnly?, attachSchema?} |

**Examples:**

```
# Get all commands
npx @eventcatalog/cli getCommands
```

***

## writeCommand[​](#writecommand "Direct link to writeCommand")

Writes a command to EventCatalog

**Arguments:**

| Name    | Type | Required | Description                                          |
| ------- | ---- | -------- | ---------------------------------------------------- |
| command | json | Yes      | Command object with id, name, version, and markdown  |
| options | json | No       | Options: {path?, override?, versionExistingContent?} |

***

## writeCommandToService[​](#writecommandtoservice "Direct link to writeCommandToService")

Writes a command to a specific service

**Arguments:**

| Name    | Type | Required | Description                          |
| ------- | ---- | -------- | ------------------------------------ |
| command | json | Yes      | Command object                       |
| service | json | Yes      | Service reference: {id, version?}    |
| options | json | No       | Options: {path?, format?, override?} |

***

## rmCommand[​](#rmcommand "Direct link to rmCommand")

Removes a command by its path

**Arguments:**

| Name | Type   | Required | Description         |
| ---- | ------ | -------- | ------------------- |
| path | string | Yes      | Path to the command |

**Examples:**

```
# Remove a command
npx @eventcatalog/cli rmCommand "/CreateOrder"
```

***

## rmCommandById[​](#rmcommandbyid "Direct link to rmCommandById")

Removes a command by its ID

**Arguments:**

| Name    | Type   | Required | Description                     |
| ------- | ------ | -------- | ------------------------------- |
| id      | string | Yes      | The ID of the command to remove |
| version | string | No       | Specific version to remove      |

**Examples:**

```
# Remove a command
npx @eventcatalog/cli rmCommandById "CreateOrder"
```

***

## versionCommand[​](#versioncommand "Direct link to versionCommand")

Moves the current command to a versioned directory

**Arguments:**

| Name | Type   | Required | Description                      |
| ---- | ------ | -------- | -------------------------------- |
| id   | string | Yes      | The ID of the command to version |

**Examples:**

```
# Version a command
npx @eventcatalog/cli versionCommand "CreateOrder"
```

***

## addFileToCommand[​](#addfiletocommand "Direct link to addFileToCommand")

Adds a file to a command

**Arguments:**

| Name    | Type   | Required | Description                      |
| ------- | ------ | -------- | -------------------------------- |
| id      | string | Yes      | The ID of the command            |
| file    | json   | Yes      | File object: {content, fileName} |
| version | string | No       | Specific version                 |

***

## addSchemaToCommand[​](#addschematocommand "Direct link to addSchemaToCommand")

Adds a schema to a command

**Arguments:**

| Name    | Type   | Required | Description                       |
| ------- | ------ | -------- | --------------------------------- |
| id      | string | Yes      | The ID of the command             |
| schema  | json   | Yes      | Schema object: {schema, fileName} |
| version | string | No       | Specific version                  |

***

## commandHasVersion[​](#commandhasversion "Direct link to commandHasVersion")

Checks if a specific version of a command exists

**Arguments:**

| Name    | Type   | Required | Description           |
| ------- | ------ | -------- | --------------------- |
| id      | string | Yes      | The ID of the command |
| version | string | Yes      | Version to check      |

**Examples:**

```
# Check if version exists
npx @eventcatalog/cli commandHasVersion "CreateOrder" "1.0.0"
```

***
