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

BoxLang 1.0.0 Beta 23 Launched

BoxLang 1.0.0 Beta 23 Launched

The latest release of BoxLang, Beta 23, marks a significant step forward in our journey to create the ultimate dynamic language for the JVM. Packed with powerful new features, important bug fixes, and thoughtful optimizations, this update is designed to make your development experience smoother, faster, and more reliable, especially after now starting to take 100s of comments and bug reports from our community.

Luis Majano
Luis Majano
November 23, 2024
TestBox Latest Updates and News!

TestBox Latest Updates and News!

We’re thrilled to have launched the new TestBox website and TestBox 6.0! If you haven’t had a chance to explore yet, visit TestBox to discover updated documentation, powerful resources, and features that make testing more efficient than ever.

Maria Jose Herrera
Maria Jose Herrera
November 21, 2024
Is Your ColdFusion Application Ready for the Future?

Is Your ColdFusion Application Ready for the Future?

In a rapidly evolving digital world, maintaining performance, security, and scalability for ColdFusion applications is more challenging than ever. Whether you're using Lucee or Adobe ColdFusion, legacy systems can become a bottleneck for growth, innovation, and user satisfaction. The need to future-proof your ColdFusion applications has never been more critical.

But where do you start?


The Hidden Costs of an Outdated ColdFusion Application

As you...

Cristobal Escobar
Cristobal Escobar
November 21, 2024