how can i use the git style sub commands in a sub folder
i have a dir structure like so
/
index.js
libs/puppet.
./enable.js
./disable.js
im trying to write something like node index.js puppet enable or node index.js puppet disable and kick off those sub commands but not sure how to do this. Commander only looks in the root for files such as puppet-<command> and not in libs/puppet/<command>
I have the same problem. Do you figure it out?
Try reading conquering commander its a few slides glossing the pros and cons of commander. Then view the starter project, more specifically the command-loader(or loader) module. I'm sure you'll be able to re-engineer for your own purposes.
Good luck.
@selbest late reply but as @phelanma mentioned that guide was what I ended up going with. The direct link to the repo is here. You'd be interested in the commands/index.js file specifically.
For me I ended up going a slightly different route by naming my "commands" folder as "libs" but my loader is mostly identical (with the exception i pass in config as a second arg and then pass it to the individual sub commands) you can see my exact code below for the commandLoader.
const fs = require('fs')
const path = require('path')
module.exports = function commandLoader(program, config) {
const commands = {}
const loadPath = path.dirname(__filename)
// Loop though command files
fs.readdirSync(loadPath).filter(function (filename) {
return (/\.js$/.test(filename) && filename !== 'index.js')
}).forEach(function (filename) {
const name = filename.substr(0, filename.lastIndexOf('.'))
const command = require(path.join(loadPath, filename))
commands[name] = command(program, config)
})
return commands
}