Register a custom command located in my own directory or within my app folder

I have a script in my coldbox application that I would like to run as a commandbox command. I don’t want to register this command by putting in the ~./Commandbox/cfml/modules/ folder.

The script creates the CRUD operations for 3 layers: 1) sql stored procedures 2) the routes, handlers, and modal services within a specified coldbox module 3) and angular routes/controllers/services. Still in the works!

The script lives in my coldbox application

My cb app looks like this:



So how do I register this crud command for Commandbox?

Why don’t you want it installed into CommandBox’s modules folder? You can easily link a module with “package link” which makes it behave as though it’s installed which is perfect for testing a module before you publish it for real.

But let’s back up for a minute. What is the ultimate goal of these scripts? Do you wish to

  1. use them only for yourself on this project
  2. share them with others on your team, but noone else
  3. Share them with the world so anyone can install and use them?

If your answer is #1, create them as task runners, which are simply portable CFCs that can live in a build folder to be run ad-hoc whenever you want.
If you’re answer is #2, create a private package and publish it to ForgeBox, linking it locally to test easily
If you’re asking is #3, create a public package and publish it to ForgeBox, linking it locally to test easily.

Also, on a side note, I think you’re mixing your modules together a bit. You have a CommandBox command inside of a ColdBox app which doesn’t make sense. If you want to share logic/services between your app and your Commands/task runners, that’s fine-- just separate those services into a standalone module and set it as a dependency to both your app and your commandbox command. Or, in the case of a task running just sitting in a build folder, use loadModule() to selectively load in these modules to the CLI context.

Answer is #2. So thats a good idea. I will look into publishing the private package next. But I should add that I was assuming I could somehow run the command in the context the coldbox application so I can have access to the coldfusion admin datasources. But I’m pretty sure you are going to tell me thats not how commandbox works. I’m not using box server to spin up this coldbox application.

Running the script in the browser is working fine, and I can run sql scripts as well. I suppose via my commandbox command I’d have to setup microsoft sql server connection settings - separate from ACF.

Any more direction you can give me now?

You are correct, that’s not how CommandBox works. When you run CFML Code from the CLI, it’s a separate Java process that has nothing to do with the Java process running your server. Now, that said, you can certainly create JDBC connections and such from the CLI.

Thank you brad.