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.

Add Your Comment

Recent Entries

Into the Box 2024 - Conference Slides are out!

Into the Box 2024 - Conference Slides are out!

Did you miss the live event? Get a glimpse of the fantastic content our speakers covered by reviewing their slides. Dive into topics like AWS, Cloud, Hosting, Migration, Security, CFML, Java, CommandBox, ContentBox, and more. Don't miss these valuable resources, and join us for upcoming events!

Maria Jose Herrera
Maria Jose Herrera
July 03, 2024
Ortus June 2024 Newsletter!

Ortus June 2024 Newsletter!

Welcome to the latest edition of the Ortus Newsletter! This month, we're excited to bring you highlights from our sessions at CFCamp and Open South Code, as well as a sneak peek into our upcoming events. Discover the latest developments in BoxLang, our dynamic new JVM language, and catch up on all the insightful presentations by our expert team. Let's dive in!

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang June 2024 Newsletter!

BoxLang June 2024 Newsletter!

We're thrilled to bring you the latest updates and exciting developments from the world of BoxLang. This month, we're diving into the newest beta release, introducing a new podcast series, showcasing innovative integrations, and sharing insights from recent events. Whether you're a seasoned developer or just getting started, there's something here for everyone to explore and enjoy.

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024