---
title: Writing Your Own Commands
summary: Build a custom command in a module, document it with help, and see which modules already extend CommandBox.
icon: phosphor-duotone:puzzle-piece
tags: [course]
---

A task lives in one project. A command is global, shipped inside a module. In this lesson you will create a command and give it help text.

## A module with a command

A module is a folder with a `ModuleConfig.cfc`. Put it in `~/.CommandBox/cfml/modules/`.

```cfml title="modules/test/ModuleConfig.cfc"
component {
  function configure() {}
}
```

Every CFC in the module's `commands/` folder becomes a command. The only requirement is a `run()` method.

```cfml title="modules/test/commands/Hello.cfc"
component {
  function run() {
    return 'Hello World!';
  }
}
```

Reload the shell, then run it:

```bash
box reload
box hello
```

## Namespaces

Nest the CFC in a folder and the folder name becomes the namespace. `commands/say/Hello.cfc` is called as:

```bash
box say hello
```

## Document it with help

A Javadoc style comment on the component is the command's help text. Comments on the arguments describe each parameter.

```cfml title="modules/test/commands/Hello.cfc"
/**
* Greets someone by name.
*
* {code:bash}
* hello Luis
* {code}
**/
component {

  /**
  * @name.hint Who to greet
  */
  function run( required string name ) {
    return 'Hello #name#!';
  }

}
```

```bash
box hello help
```

Argument names are the flags and parameters users type, and tab completion is built from the same metadata.

## Modules that extend CommandBox

Install them from ForgeBox with `box install`. Popular ones:

- `coldbox-cli`
- `contentbox-cli`
- `commandbox-boxlang`
- `testbox-cli`
- `commandbox-migrations`
- `commandbox-cfconfig`
- `commandbox-docbox`
- `commandbox-bullet-train`

!!! tip "See what you have"
    Run `box help` to list every namespace and command available, including those added by modules.

## Recap

- A command is a CFC with a `run()` method inside a module's `commands/` folder.
- Subfolders make namespaces, and a comment on the component is the `help` text.
- Use `box reload` after changes and `box install` to add community modules.
