我目前使用的是第三方应用程序,它在REPL模式下使用Vorpal。我正在尝试使用Vorpal中的exec函数自动执行一些部署配置,以便在我的项目中使用。在出现提示符之前,一切都正常工作。在这一点上,我的执行挂起,我不能前进,直到我做了一些手动步骤(这不是我想要的)。
我看了一下文档,但没有提到有什么诀窍。我希望避免对已经存在的代码进行深入的更改,但如果需要使用选项,我会这样做。
下面是我的代码示例:https://gist.github.com/gretro/b67aa364967c3fa2c82279b7e4236c2e
有没有什么我遗漏的东西,或者有什么技巧可以用来做我需要做的事情?
发布于 2018-07-29 00:53:05
下面的代码可能会有所帮助,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: fdfsdfhttps://stackoverflow.com/questions/44766036
复制相似问题