Brad Wood

March 02, 2017

Spread the word

Share your thoughts

There's a lot of command tools out there written by developers to help them automate all sorts of tasks from code refactoring, linting, and builds. Node has become a popular tool to write reusable tools that can be run from the command line, but many CF developers don't realize that CommandBox has allowed developers to do this nativley in CFML for years now.

CLI Goodness

Writing a CLI tool sounds a little scary, but it's actually very easy-- as easy as a CFC containing a single method. Let's take a look at a real CLI command that you can run on CommandBox:


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

Hey, that's not so bad is it? By convention, the name of your command will be the same as the CFC name (hello) which means you'd run the above like so from any operating system:

$> box hello
Hello World!

Now you can add this command to Jenkins builds, package scripts, cron jobs, cfexecute, or just from your local bash shell!


But there's more you can do. A lot more. I'm a little biased, but I honestly think CommandBox is better than Node in several of these areas. Check out this cool stuff you can add into your new command line tools:

  1. Nest commands into names spaces like coldbox create app, coldbox create module, etc
  2. Accept named or positional parameters with no manual parsing or additonal libs needed.
  3. Users are automatically prompted for missing required params
  4. Easy boolean flags out-of-the-box like --force
  5. Super-easy ANSI formatting like font colors and decoration like print.blueText( 'sad panda' )
  6. Bullt-in tab completion for your command names and parameter name/values
  7. Automatic help screens generated right from your CFC's metadata
  8. Complete interactivity with your users via helper methods like ask(), confirm(), and waitForKey()
  9. Automatically send back proper exit codes to the OS when an error happens
  10. Nice helpers for finding current working directory, expanding relative paths, and getting terminal size
  11. Even access a database via on-the-fly JDBC connections.

Where do I start?

Want to play around with all this? 100% of what I mentioned above is documented right here in our docs:

That page will walk you through creating your first command in only a few minutes. And when you're ready to share your work with the world, just stick it in a GitHub repo and use the publish command to send it up to ForgeBox. Setting up some package scripts will even help manage all your versions. When I want to make changes to a command live, I just have to type this and my package scripts take care of tagging the repo, pushing to GitHub, and publishing the latest version to ForgeBox!

CommandBox> bump --minor


Some people like to learn from checking out existing projects. Feast your eyes on these example CommandBox modules that have custom commands in them:

Any of those projects above can be installed globally into your local CommandBox installation just like this:

CommandBox> install commandbox-chuck-norris

Get going

OK, you have the tools. You're a CF dev and it's time you put some of your totally aweseome ideas into action. Go and create some sweet stuff, then show your friends and watch their suprise when you tell them your new CLI tooling is written in ColdFusion!

Add Your Comment


Mar 02, 2017 17:46:09 UTC

by Adam Cameron

Interesting stuff. Given you mention it, it'd be good if you could actually objectively (or, hey, even subjectively!) quantify how "CommandBox is better than Node in sevearl of these areas".

Mar 02, 2017 18:25:51 UTC

by Luis Majano

Thanks for your comment Adam! I am sure that would be a cool blog entry to do separately so as to distinguish our differences or do a compare-contrast objectively. Inherently, there are architectural and language differences, so we cannot compare apples to apples in many areas. However, there are many areas we can do this and we have improved upon NPM and Node CLI as well. We had the pleasure of analysing how these tools work and be able to take the best out of them and port what we thought would be best over to CommandBox. Off the bat our caching strategy for artifacts is part of CommandBox which does not exist in NPM, which makes CommandBox package resolving and installation way faster and better performant. I'll let Brad comment (While I go get some popcorn)

Mar 02, 2017 20:03:37 UTC

by Adam Cameron

G'day Luis. I reckon of the article was just "commandbox is good, and you can do this", then it's fair cop to not justify one's self. But an article which makes a point of saying x is better than y, then it's *slightly* disingenuous to just say it rather than actually explaining / showing how x is actually better than y. This kinda reads more like an advert than exposition. But I guess advertising *box stuff *is* Brad's raison d'etre ;-) That said: it's a good teaser for commandbox commands. And I look fwd to reading a more meaningful comparison. Cheers!

Mar 02, 2017 20:05:00 UTC

by Adam Cameron

PS: your comments system are swallowing paragraph breaks. My previous comment wasn't one run-on thought, it was three paras. Maybe you need a FormatBox or something ;-)

Mar 03, 2017 01:55:30 UTC

by Brad Wood

Hi Adam, that's a fair question to ask. I've expounded on the way I think CommandBox is better than npm at creating CLI tools, but I did so on my personal blog as to not clutter the comments here.

Recent Entries

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023