Skip to content

Instantly share code, notes, and snippets.

@subk
Created May 1, 2016 14:38
Show Gist options
  • Save subk/c000508539e8c03e8ece650943264a42 to your computer and use it in GitHub Desktop.
Save subk/c000508539e8c03e8ece650943264a42 to your computer and use it in GitHub Desktop.
vorpal sub command autocomplete test
const Vorpal = require('vorpal');
const vorpal = new Vorpal();
const clouds = [
{ name: 'google', env: [ 'gce', 'gke'] },
{ name: 'amazon', env: [ 'ec2', 'ec2_container'] }
];
vorpal
.command('deploy [cloud] [type]')
.autocomplete(() => {
const args = vorpal.ui.input().split(' ');
if (args.length > 2) {
return clouds.find(cloud => cloud.name === args[1]).env;
}
return clouds.map(cloud => cloud.name);
})
.action(function (args, cb) {
console.log(args);
cb();
});
vorpal
.delimiter('>')
.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment