Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Support subcommands #2

Closed
artegoser opened this issue May 10, 2021 · 0 comments
Closed

Support subcommands #2

artegoser opened this issue May 10, 2021 · 0 comments
Labels
invalid This doesn't seem right
Projects

Comments

@artegoser
Copy link
Owner

fix this with this

const { Command } = require('commander');
patchCommander(Command);

function patchCommander(Command) {
  Command.prototype.forwardSubcommands = function() {
      var self = this;
      var listener = function(args, unknown) {
          args = args || [];
          unknown = unknown || [];
          var parsed = self.parseOptions(unknown);
          if (parsed.args.length) args = parsed.args.concat(args);
          unknown = parsed.unknown;
          if (unknown.includes('--help') || unknown.includes('-h')) {
              self.outputHelp();
              process.exit(0);
          }
          self.parseArgs(args, unknown);
      };
      if (this._args.length > 0) {
          console.error('forwardSubcommands cannot be applied to command with explicit args');
      }
      var parent = this.parent || this;
      var name = parent === this ? '*' : this._name;
      parent.on('command:' + name, listener);
      if (this._alias) parent.on('command:' + this._alias, listener);
      return this;
  };
}
@artegoser artegoser added the invalid This doesn't seem right label May 10, 2021
@artegoser artegoser added this to High priority in Bugs May 10, 2021
@artegoser artegoser removed this from High priority in Bugs May 10, 2021
@artegoser artegoser added this to To do in Roadmap May 10, 2021
@artegoser artegoser moved this from To do to Done in Roadmap May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
Development

No branches or pull requests

1 participant