Blog

What's New in Commandbox 4 — Ad-hoc Module Loading

Eric Peterson July 18, 2018

Spread the word

Eric Peterson

July 18, 2018

Spread the word


Share your thoughts

CommandBox has a new super power for your task runners — you can now load ad-hoc modules on the fly!

The syntax is pretty straight-forward: call loadModule passing in the path to the module you want to load.

Let me show you the beginning of a task runner I whipped up to create a PR to add adobe@2018 to all of our Travis builds. I wanted to use Hyper, an HTTP client, instead of raw cfhttp calls. First, I installed Hyper from ForgeBox in to the same folder as my task runner. Then I referenced the relative path in my loadModule call.

function run(
    string searchQuery,
	string newEngine,,
	string user,
	string forkUser,
	string githubToken
) {
    loadModule( "modules/hyper" );
    var githubAPI = getInstance( "HyperBuilder@hyper" );
    githubAPI.defaults.setAutoSerializeQueryString( false );
    githubAPI.defaults.setBaseUrl( "https://api.github.com" );
    githubAPI.defaults.setHeader( "Authorization", "token #githubToken#" );

    var results = githubAPI.get( "/search/code", {
        "q" = "#encodeForURL( searchQuery )#+user:#user#+filename:.travis.yml"
    } );

    /* .... */
}

Now I can update all my own personal modules that use Travis CI to test on Adobe 2018 with my task runner:

CommandBox:>task run taskFile=AddEngineToTravisBuilds :searchQuery=adobe@2016 :newEngine=adobe@2018 :user=elpete :forkUser=elpete :githubToken=hahahahahaha

You can check out the full code here in this gist.

There you have it! It's even easier to use task runners now for those one off commands. loadModule is available on the latest stable version of CommandBox (4.1.0).

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