Saturday, 18 October 2014

TickintheBox

G'day:
I watched a good amount of bickering between two fellas who should know better last night:


(click through and read the "conversation" if you want to. I'll not reproduce it here as it's a bit embarrassing for the participants, I think).

Also, I "published" some misinformation of my own about CommandBox a day or so ago (as a comment on Cutter's blog:  "What's Wrong With ColdFusion - 2014 Edition"). So I figured I owed to Brad and Luis to actually have a look at CommandBox (which I do like the sound of, see "Ortus does what Adobe / Railo ought to have done...").

I set a task for myself: locate CommandBox, download and install it, run a preexisting file, and effect the same code via its REPL.

Locate

Couldn't be easier: it's the first match on Google for "commandbox" (no surprise I guess).

Download

The download option is front and centre (well: top and right), and gives options for various installs, clearly labelled:



I opted for the all-inclusive Windows 64-bit JRE one. It's 80MB or so, and downloaded quickly.

Install

It's just an unzip. I unzipped it into my C:\bin dir, and put C:\bin\commandbox on my path (I am guessing/expecting that's all I need to do to run it from anywhere).

Test File

I opened a command prompt and navigated to my C:\temp dir, and (manually) created this test file:

<cfscript>
// gdayWorld.cfm
msg = "G'day World"
echo(msg)
</cfscript>

CLI

Here's a reproduction of my CLI session (including me being a dick a coupla times):

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\adam.cameron>cd \temp

C:\temp>cat > gdayWorld.cfm
'cat' is not recognized as an internal or external command, operable program or batch file.

C:\temp>notepad gdayWorld.cfm

C:\temp>box exec gdayWorld.cfm
Configuring CommandBox home: C:\Users\adam.cameron\.CommandBox (change with -Com
mandBox_home=/path/to/dir)
Library path: C:\Users\adam.cameron\.CommandBox\lib
Initializing libraries -- this will only happen once, and takes a few seconds...

..............................................
Libraries initialized
ERROR: Command "exec gdayWorld.cfm" cannot be resolved.  Please type "help" for
assistance.

A coupla things:

  • seems I don't have whatever extension one needs to run things like cat on a Windows box. This all works on my machine at work, and just assumed it was part of the Windows shell these days. Oops.
  • I misremembered what Brad had said y/day was the command to execute a CFM file from the command prompt: it's not exec. This is just me not RTFMing.
  • The installation time was more like a few minutes (maybe two?), not a few seconds.

So I ask for help:

C:\temp>box help

**************************************************
* CommandBox Help
**************************************************

Here is a list of commands in this namespace:

 browse
 cat
 cd
 clear
 cp
 delete
 dir
 echo
 edit
 execute
 help
 history
 info
 mkdir
 mv
 prompt
 pwd
 quit
 recipe
 repl
 run
 tail
 touch
 upgrade
 version


Here is a list of nested namespaces:

 artifacts
 cachebox
 coldbox
 contentbox
 docbox
 forgebox
 game
 logbox
 namespace
 package
 server
 task
 testbox
 wirebox


To get further help on any of the items above, type "help command name".

OK, so it's execute, not just exec:

C:\temp>box execute gdayWorld.cfm

G'day World

Perfect: it worked. Nice. Note: as it's gotta start up a Railo instance each time I run something, this takes about 7-8sec to execute. This is pretty slow, but not CommandBox's fault, I think.

REPL

OK, that's good, but I want a REPL too.

C:\temp>box

  _____                                          _ ____
 / ____|                                        | |  _ \
| |     ___  _ __ ___  _ __ ___   __ _ _ __   __| | |_) | _____  __
| |    / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` |  _ < / _ \ \/ /
| |___| (_) | | | | | | | | | | | (_| | | | | (_| | |_) | (_) >  <
 \_____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|____/ \___/_/\_\ v1.0.0+00168


Welcome to CommandBox!
Type "help" for help, or "help [command]" to be more specific.
CommandBox:temp> help

**************************************************
* CommandBox Help
**************************************************

Here is a list of commands in this namespace:

 browse
 cat
 cd
 clear
 cp
 delete
 dir
 echo
 edit
 execute
 help
 history
 info
 mkdir
 mv
 prompt
 pwd
 quit
 recipe
 repl
 run
 tail
 touch
 upgrade
 version


Here is a list of nested namespaces:

 artifacts
 cachebox
 coldbox
 contentbox
 docbox
 forgebox
 game
 logbox
 namespace
 package
 server
 task
 testbox
 wirebox


To get further help on any of the items above, type "help command name".

Nice one. Very polished. So to get the REPL, I type REPL:

CommandBox:temp> repl
Enter any valid CFML code in the following prompt in order to evaluate it and print out any results (if any)
Type 'quit' or 'q' to exit!
CFSCRIPT-REPL: msg  = "G'day world"
=> "G'day world"
CFSCRIPT-REPL: <cfoutput>#msg#</cfoutput>


ERROR

Syntax Error, Invalid Construct


CFSCRIPT-REPL: echo(msg)
=> G'day world
CFSCRIPT-REPL:


It worked! Note that it takes CFScript rather than tags, but that is perfect. We'd not be running view code in a REPL, so there's no point supporting tags.

Obviously there's a bunch of other stuff that CommandBox does - package management via ForgeBox integration, application installers (one can install PresideCMS and set up a Preside website from within CommandBox, for example), but I have other things to do today, and I really just wanted to do the proof of concept.

Concept proven.

--
Adam