All pages
Powered by GitBook
1 of 5

Loading...

Loading...

Loading...

Loading...

Loading...

Helpful Commands

Here are some helpful commands that can come in handy when writing task runners for automating builds via CFML. Of course, since these are just commands, they can be run directly from the CLI as well by you.

Token Replacements

One common thing in builds is replacing a token placeholder across all files, or perhaps certain files defined by a file globbing pattern. We've got a special command for that.

From the CLI

tokenReplace path=/tests/*.cfc token="@@version@@" replacement=`package version`

From CFML

command( 'tokenReplace' )
    .params( 
        path = "/tests/*.cfc",
        token = "@@version@@",
        replacement = command( 'package version' ).run()
     )
    .run();

Code Quality Tools

Here's some commands to help with code quality. You can use them as a one-time clean up and then use them as part of your regular build to maintain your coding rules.

Normalize Indents (Tabs vs Spaces)

Ahh, the age-old debate of tabs vs spaces. Make sure you have a solid discussion with your team and decide which one is correct (tabs, obviously!) and then use this command to implement it across your entire code base.

From the CLI

From CFML

Remove Trailing Spaces

Removes trailing whitespace from the ends of your lines.

From the CLI

From CFML

Add final EOL character

Makes sure the last line of every source file has an EOL character.

From the CLI

From CFML

Checksums

Another very common requirement for builds is generating checksums on your files. We've got you covered here now as well. Run checksum help for even more options.

From the CLI

ask and confirm

Here are some fun commands for user interactivity in the shell. You can use these as part of a recipe or a nice "one-liner".

ask

The ask command is similar to the ask() method in Task Runners. It requires an interactive terminal and will ask the user a question and return their answer. It is meant to be changed with other commands.

or with default values

From CFML

Checksum all files in a directory

You can provide a file globbing pattern to receive a checksum for all files in a directory that match that pattern.

Output format

The checksum command also supports some other popular formats for outputting checksums. The default format is checksum.

Write out checksums

The checksum command will also write out a file that contains the hash which is a common requirement for builds that produce artifacts.

Write checksum(s) to a file named after the original file plus a new extension. This will create a file called myFile.zip.md5.

Control the file extension like so. (--write is optional when supplying an extension) This will create a file called myFile.zip.hash.

Verify a file against an existing checksum

You can check a file against an existing checksum to make sure the file hasn't changed.

or with masked input

Or fun stuff like this

confirm

The confirm command will ask the user a yes/no question and return a passing or failing exit code from the command based on the answer.

Remember the && operator will only execute the second command if the first command returns an exit code of 0.

set color=`ask "favorite Color? "`
echo "you said ${color}"
ask question="Who is cool? " defaultResponse="Balbino!"
ask question="What is your password? " mask=*
utils normalize-indents **.cf?
command( 'indents' )
    .params( '**.cf*' )
    .run();
utils remove-trailing-spaces **.cf*
command( 'rts' )
    .params( '**.cf*' )
    .run();
utils add-eol-at-eof **.cf*
command( 'eol' )
    .params( '**.cf*' )
    .run();
checksum file.txt
checksum path=build.zip algorithm=SHA-256
command( 'checksum' )
    .params( 'file.txt' )
    .run();

command( 'checksum' )
    .params( path = 'build.zip', algorithm = 'SHA-256' )
    .run();
checksum *.cfc
checksum path=**.cfc format=checksum
checksum path=**.cfc format=sfv
checksum path=**.cfc format=md5sum
checksum myFile.zip md5 --write
checksum path=myFile.zip extension=hash --write
checksum path=myFile.zip verify=2A95F32028087699CCBEB09AFDA0348C
ask "Secret phrase: " | assertEqual "mockingbird" || echo "access denied!" && exit 1
confirm "do you want to update your packages? " && update