Closed lorneb closed 9 years ago
The mode
command is probably the closest option you have to this. Vorpal doesn't support namespacing command sets per se, but when you separate out command groups by spaces, such as get *
, it groups them accordingly in the help menu. You can then use the catch
command to perhaps simulate the freezing of a "directory" or something.
Like if there was a command get foobar
, and you did a command like cd get
, you could reset your delimiter to app~$ get:
or something. Then the foobar
string, when executed, it would call the catch
command (as there is no foobar
command). The catch command could know you were in the get
directory, and then programmatically execute get foobar
for the user.
In other words, it isn't strictly supported, but you could work it.
Does that help?
Wouldn't it be possible to instanciate vorpal multiple times and give different commands to these instances? The main instance could then provide different modes, whose .action() function simply delegates to a certain instance.
Or would there be problems with multiple different session objects?
Haha - @AljoschaMeyer you're really smart! Great idea - Vorpal actually supports this! The vorpal.show()
command attaches a specific instance to the UI.
Try this:
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:'),
}
Excellent thanks very much that certainly has given me a great start. Are you happy to take questions via the Issues, or is there a better place?
No probs :)
I'd wouldn't mind taking the questions to Stack Overflow: Vorpal is in its infancy (haven't started promoting it yet), but I fully intend it to become a major library. Your question above is a perfect SO-type question for it.
And If you have questions there and I don't see them, you can ping me on Gitter (see badge on readme) to remind me its there :)
Closing this.
I think you have a bug (version 1.4.0)
If you run example from above, and try to "switch a" twice, the instance will exit !?
$ node switcher.js
a: switch a
a: switch a
$
k
I'm having issues with my history when working on different instances of Vorpal. Do we need to create a new vorpal each time we switch instances? I would think you would only run new once to create a new instance then be able to switch between them by just using show. I'm not even really sure that is my problem at the moment.
Hi, I've been working on the issue of multiple instances for a while now and was wondering you any of you can comment on why this isn't working for me.
Running your example above, in my test below, 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 the autocomplete directory results four times. Making it almost unusable. Even without the autocomplete, a regular tab will return 4 sets of commands. Can anyone comment on what I'm doing wrong please?
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('sw
var instances = { 'a': new Vorpal().use(swap).delimiter('a:'), 'b': new Vorpal().use(swap).delimiter('b:'), 'c': new Vorpal().use(swap).delimiter('c:'), }
Hi not sure if this even part of what Vorpal is all about, I did see the mode options, but what I wanted to know was