Blog

Let’s get cooking with CommandBox Recipes!

Luis Majano February 13, 2015

Spread the word

Luis Majano

February 13, 2015

Spread the word


Share your thoughts

One exciting feature about CommandBox is the ability to group commands together into a lovingly little file we call, a recipe.  We even gave it its own extension, .boxr.  This little gem will allow you to automate several commands from your native shell, it will be faster to use our recipe command that allows you to run several CommandBox commands at once. This will allow you to only load the CommandBox engine once for all those commands, but still be dumped back at your native prompt when done. Recipes can also just be useful for a series of commands you run on a regular basis, from test executions, to compressing files, the possibilities are endless.  

Below is a simple example of how to create a recipe and execute it.  For further insight, we recommend you read our chapter on recipes in our CommandBox book.

How to start?

Recipes are modern batch files or shell scripts for those unix fans.It has the capability to execute commands just like if you are in the shell, have comments and even have the ability to do argument binding. Technically a recipe can have any file extension, but the default recommendation is .boxr which stands for "box recipe". Lines that start with a # will be ignored as comments. just like in many batch files.  Here is a nice example:

# Named param
echo "Hello $name, we are ready to start your recipe"
# Positional param
echo "Hello $1, we are ready to start your recipe"


# Start with an empty folder
rm mySite --recurse --force
mkdir mySite
cd mySite

# Initialize this folder as a package
init name=mySite version=1.0.0 slug=mySlug

# Scaffold out a site and a handler
coldbox create app mySite
coldbox create handler myHandler index

# Add some required package
install coldbox
install cbmessagebox,cbstorages,cbvaidation

# Set the default port
package set defaultPort=8081

# Start up the embedded server
start

 

Executing Your Recipe

You will use the recipe command in order to execute recipes.  You can find much more information about the recipe command by typing recipe help or visiting the API Docs.

recipe myrecipe.boxr

If you have named parameters you would execute it like this:

recipe recipeFile=myrecipe.boxr name=Luis

If you have positional parameters you would execute it like this:

recipe myrecipe.boxr Luis

As you can see, very nicely you can bind your recipes with dynamic content and automate pretty much anything.  We even have a contribution type in ForgeBox for all CommandBox recipes, so please share them with the world.

Add Your Comment

(2)

Dec 03, 2018 09:36:48 UTC

by Travis

Links on this post are broken.

Dec 03, 2018 16:00:06 UTC

by Brad Wood

Thanks, I've updated the links.

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