zeroarg
zeroarg copied to clipboard
Multi-command
:wave:
From ur blog:
Supporting multiple commands as multiple functions
Curious how you'd think about structuring this? Something like this?
/**
* top-level help here
*/
module.exports = {
/**
* one command's help
*/
commandA: function(a, b, c) { ... },
/**
* another command's help
*/
commandB: function(a, b, c) { ... }
}
Would this then support:
cli --help
cli commandA --help
cli commandB --help
Could the nesting go into deeper sub-commands?
Hey Ryan!
Yeah! Within the current setup, it'd be a little more like
module.exports = zeroarg({
/**
* one command's help
*/
commandA: function(a, b, c) { ... },
/**
* another command's help
*/
commandB: function(a, b, c) { ... }
})
And zeroarg would know if the module was not the entry point and just be an identity function if not.
sub-sub commands... yes if supported by the backend, but afaik yargs doesn't support command nesting, and if commander does, I'm misreading the docs.
Am I correct that it is important that you bring a function to zeroarg, in order to take advantage of function.toString()
as the documentation source?
That is, would it need to look like:
module.exports = zeroarg(function() {
return {
/**
* one command's help
*/
commandA: function(a, b, c) { ... },
/**
* another command's help
*/
commandB: function(a, b, c) { ... }
};
});
Maybe I just didn't quite understand this:
And zeroarg would know if the module was not the entry point and just be an identity function if not.
It does look like yargs has support for sub-command nesting, at least via the .commandDir()
method. But I'm not sure that'll work for what's going on here.