dthree / vorpal

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

Switching between instances will exit #56

Closed jstrika closed 8 years ago

jstrika commented 8 years ago

In one of your examples, you demonstrated how to switch between multiple instances.

function switch(vorpal) {
  vorpal.command('switch <instance>')
    .action(function (args, cb) {
      instances[args.instance].show();
    });
  return vorpal;
}

var instances = {
  'a': new Vorpal().use(switch).delimiter('a:'),
  'b': new Vorpal().use(switch).delimiter('b:'),
  'c': new Vorpal().use(switch).delimiter('c:'),
}

Using version 1.4.0, it does work on first ''switch'', but switching again to the same instance will exit.

$ node switcher.js
a: switch a
a: switch a
$
dthree commented 8 years ago

Erm, could you please try adding a callback to that method? i.e.

function switch(vorpal) {
  vorpal.command('switch <instance>')
    .action(function (args, cb) {
      instances[args.instance].show();
      cb();
    });
  return vorpal;
}
jstrika commented 8 years ago

Yep, that did the trick ;)

For others to benefit': this feature allows us to create navigation between multiple menus. And if you push the instance name to an Array, you can add commands such a "back" or "show breadcrumbs" that can be shared between menus.

BTW: @dthree - great job with Vorpal !

dthree commented 8 years ago

Great and thanks!

:smile: