dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.63k stars 278 forks source link

subcommands in mode #286

Open NonPolynomial opened 6 years ago

NonPolynomial commented 6 years ago

is there a recommended way to do subcommands for modes?

ORESoftware commented 6 years ago

maybe include an example of what you want to do?

ORESoftware commented 6 years ago

is this similar to your issue? https://github.com/dthree/vorpal/issues/289

b4dnewz commented 6 years ago

@NonPolynomial did you find a good pattern or did you give up?

it would be awesome to have an example for this, like the sub-commands in commanderjs examples

I've looked at the code of [cash]() to see a working example

config.commands.forEach(cmd => {
  try {
    const mod = require(`../lib/commands/${cmd}`)
    program.use(mod);
  } catch (e) {
    program.log(`Error loading command ${cmd}: `, e);
  }
})

but on the sub-commands files I do this:

module.exports = (program, options) => {
  program
    .command('foo list')
    .action((args, callback) => {
      callback();
    });

  program
    .command('foo scan')
    .action((args, callback) => {
      callback();
    });
}

but.. I've understood from this issue that the mode needs to be refactored in order to show the sub-commands as a stand-alone cli.

I don't know if it can help but I've almost archived what I wanted.