Writing Your Own Commands

Build a custom command in a module, document it with help, and see which modules already extend CommandBox.

On this page

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/.

component {
  function configure() {}
}

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

component {
  function run() {
    return 'Hello World!';
  }
}

Reload the shell, then run it:

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:

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.

/**
* Greets someone by name.
*
* {code:bash}
* hello Luis
* {code}
**/
component {

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

}
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
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.
Edit this page Download Markdown Last updated Nov 30, 2026, 8:08:15 PM Report an issue
Lesson 13 of 15 - Learn CommandBox