我当前正在使用在 REPL 模式下使用 Vorpal 的第 3 方应用程序。我正在尝试使用 Vorpal 中的 exec
函数自动执行一些部署配置,以便在我的项目中使用。一切正常,直到出现提示。此时,我的执行挂起,并且在执行一些手动步骤之前我无法继续进行(这不是我想要的)。
我查看了文档,但没有提到任何技巧可以做到这一点。我希望避免深入更改已经存在的代码,但如果需要使用选项,我会这样做。
这是我的代码示例: https://gist.github.com/gretro/b67aa364967c3fa2c82279b7e4236c2e
有什么我错过的东西或者可以用来做我需要做的事情的技巧吗?
最佳答案
下面的代码可能会有所帮助,exec 命令可用于在带或不带命令行参数的情况下调用 vorpal 命令,如果不带命令行参数,则会提示输入用户名和密码。这就是你所追求的吗?
/*jshint esversion: 6 */
const vorpal = require('vorpal')();
vorpal
.delimiter('vorpal$')
.command('logon [uname] [pwd]', 'logs you on.')
.action(function(args, callback) {
var the_username = "";
var the_password = "";
if (args.uname !== undefined) {
the_username = args.uname;
the_password = args.pwd;
console.log("The username was: "+the_username);
console.log("The password was: "+the_password);
} else {
let questions = [
{
type: 'input',
name: 'username',
message: 'Enter username: '
},
{
type: 'password',
name: 'password',
message: 'Enter password: '
}
];
this.prompt(questions, function (answers){
the_username = answers.username;
the_password = answers.password;
console.log("The prompted username was: "+the_username);
console.log("The prompted password was: "+the_password);
});
}
});
vorpal.show();
// Uncomment the appropriate exec command, the one with arguments,
// or the one that prompts for the username/password.
// vorpal.exec('logon auser apassword');
vorpal.exec('logon');
执行如下:
vorpal$
The username was: auser
The password was: apassword
或者像这样:
vorpal$
Enter username: fdfss
Enter password: ******
The prompted username was: fdfss
The prompted password was: fdfsdf
关于javascript - Vorpal - 如何使用提示执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44766036/