Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-command #1

Open
rclark opened this issue May 5, 2017 · 2 comments
Open

Multi-command #1

rclark opened this issue May 5, 2017 · 2 comments

Comments

@rclark
Copy link

rclark commented May 5, 2017

馃憢

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?

@tmcw
Copy link
Member

tmcw commented May 9, 2017

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.

@rclark
Copy link
Author

rclark commented May 9, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants