Skip to content

Multi-command #1

Open
Open

Description

@rclark

👋

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?

Activity

  1. tmcw commented on May 9, 2017

    @tmcw
    Member

    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.

  2. rclark commented on May 9, 2017

    @rclark
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions