Created
May 1, 2016 14:38
-
-
Save subk/c000508539e8c03e8ece650943264a42 to your computer and use it in GitHub Desktop.
vorpal sub command autocomplete test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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