Multiple Instances of Vorpal / Switching
See original GitHub issueHi, I’ve been working on the issue of multiple instances for a while now and it seems no matter what I do I do not get what seems to be separate instances of Vorpal. What I’m trying to accomplish is having multiple instances of vorpal that use a different set of commands(via use) and being able to switch through them.
In Case-1 below I try an example #56 given by dhtree as a solution to switching via multiple instances- I experience a lot of unexpected behavior, one of them being issues with tab-tab to get list of commands, and same for autocomplete using autocomplete-fs. It will return the commands 4 times for each tab-tab or as well as the autocomplete-fs directory results. Which suggests to me that there is only one instance being created of Vorpal. Even without the autocomplete, a regular tab will return 4 sets of commands. Aside from this behavior, command history also does not work properly when switching for me - the history is shared between the instances or new history is not recorded due to some unknown conflict.
In Case-2 which is another example given by dhtree the results are same as above, to me, suggesting there are not two seperate instances of vorpal but shared.
I would even take working with one instance of Vorpal and changing the commands it uses but I do not know of any way to remove .use from the instance to remove commands you have already issued .use(commands) on. The only downside of this is that it would not have separate attributes like autocomplete history and possibly others.
I’m really hoping I’m missing something - any ideas or solutions would be greatly appreciated!
Case-1
const Vorpal = require('vorpal');
const mainVorpal = new Vorpal();
const path = require('path');
const fsAutocomplete = require('vorpal-autocomplete-fs');
mainVorpal
.delimiter('X:')
.use(swap)
.show();
function swap(mainVorpal) {
mainVorpal.command('swap')
.autocomplete(fsAutocomplete())
.action(function (args, cb) {
instances[args.instance].show();
cb();
});
return mainVorpal;
}
var instances = {
'a': new Vorpal().use(swap).delimiter('a:'),
'b': new Vorpal().use(swap).delimiter('b:'),
'c': new Vorpal().use(swap).delimiter('c:'),
}
Case-2
function swap(mainVorpal) {
mainVorpal.command('do <instance>')
.action(function (args, cb) {
console.log("walk");
cb();
});
return mainVorpal;
}
function swap2(mainVorpal) {
mainVorpal.command('say <instance>')
.action(function (args, cb) {
console.log("hello");
cb();
});
return mainVorpal;
}
const Vorpal = require('vorpal');
const chalk = Vorpal().chalk;
const unicorns = new Vorpal()
.delimiter(chalk.magenta('unicorn-land~$'))
.use(swap)
.history('unicorn-command-history');
.show()
const narwhals = new Vorpal()
.delimiter(chalk.cyan('narwhal-land~$'))
.use(swap2)
.history('narwhal-command-history');
Issue Analytics
- State:
- Created 6 years ago
- Comments:24 (2 by maintainers)

Top Related StackOverflow Question
@omidnavi sure, I can have a little look at it, probably not till tomorrow sometime.
The repo I shared grabs all the folder names in the modules directory then adds them as modules. If you used the same code you would only be able to have module/submodule folders you would probably have to do something like modules/module1/submodules/submodule1 so that you can loop over the modules and the submodules folder within each module. There are probably other ways, this was the first that came to mind.