Blog

Gavin Pickin

February 10, 2015

Spread the word


Share your thoughts

Using a command line tool, like CommandBox, you look for those feature comforts, that can make or break the UI. With CommandBox, one of the big wins, is HELP. Most command line tools allow you to type help and get some general help, but CommandBox goes a step further, you can get Help the Global Level, Namespace Help, and even help at the Command Level.

Global Help

To get an overall list of all the commands you have available to run, simply type help at the shell.

Global Help

 

Namespace Help

Next, drill down and get help on a specific namespace like server.

Namespace Help

 

Command Help

And finally, get help on a single command such as server stop. We can see the command is also aliased as just stop as well as all the possible parameters and their types along with a few sample ways to call the command.

Command Help

 

Thats great, all the built in commands have solid help, but being a community tool, what about when someone else makes a command, I’m sure they won’t have great help too.

That is where you are wrong… CommandBox uses JavaDoc comments to help generate the help for the CLI and even Tab Completion and Hints. There is no excuse for not including help in your Commands, because you can just annotate your functions and arguments/params and you have Help available for all your users.

Let's look at the stop.cfc inside CommandBox itself to see how this is generated.
A simple comment above the component is output.

  • Text outputs normally.
  • A period represents a blank line.
  • {code:bash} and {code} surround the code to make it stand out.

The comments above the run function define a hint, or description for the parameter. Tab completion is another great help when using the CLI, and CommandBox makes that easy by prompting boolean values with true/false, and parameters that include directory, destination, file or path in their names will get file system suggestions for tab complete. Of course can also give custom options, static options where you provide a list in the comment itself, or in this case, the options for Name are dynamically created from a optionsUDF called serverNameComplete that returns the list of running servers.

/**
 * Stop an embedded CFML server.  Run command from the web root of the server, or use the short name.
 * .
 * {code:bash}
 * server stop
 * server stop serverName
 * server stop serverName --forget
 * server stop --all
 * {code}
 **/
component extends="commandbox.system.BaseCommand" aliases="stop" excludeFromHelp=false {
      /**
      * @name.hint the short name of the server to stop
      * @name.optionsUDF serverNameComplete
      * @directory.hint web root for the server
      * @forget.hint if passed, this will also remove the directory information from disk
      * @all.hint If true, stop ALL running servers
      **/
     function run(
          string name="",
          string directory="",
          boolean forget=false,
          boolean all=false ){
          //Lots of code in here
     }

     function serverNameComplete() {
          return serverService.getServerNames();
     }

}

 

Help and Tab Completion is great for any CLI User, and even the commands you build can be as professional and helpful as anything else out there.
What command are you going to build?

 

More information on how to use the help when running the CLI
More information on how to build help into the commands you build.

Recent Entries

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
April 01, 2024
Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024