dthree / vorpal

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

Question: How to dynamically configure options of a command? #148

Closed tobilg closed 8 years ago

tobilg commented 8 years ago

Is it possible to configure the option list dynamically instead of statically chaining the option() to vorpal.command()?

Background is I want to be able to create my vorpal commands from some kind of metadata objects, i.e. I want to save some work for commands which work similarly by generating those commands based on a definition.

dthree commented 8 years ago

Well, you can always go back and edit a command, or remove it and re-create it, so you could re-build commands dynamically with some sort of meta data:

const options = ['toppings', 'foo', 'bar'];

for (let i = 0; i < options.length; ++i) {
  vorpal.find('metacmd').option(options[i]);
}

This is a super simple example, but you can add as much metadata as you want to it.

Another pertinent command would be vorpal.find('metacmd').remove();


Would you mind posting this on Stack Overflow? In this way, others with the same question can benefit easier!

tobilg commented 8 years ago

Thanks a lot for the fast answer. I'll post the question to SO later today.