-
-
Save Oipo/b179a5accb93b3c74ea52e6e806e4d37 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const prompt = require('prompt'); | |
prompt.start(); | |
let accepted = false; | |
while(!accepted) { | |
prompt.get([{ | |
name: 'host', | |
required: true | |
}, { | |
name: 'port', | |
required: true, | |
message: 'Port must be a number between 0 and 65535', | |
conform(value) { | |
return value === parseInt(value, 10) && value >= 0 && value <= 65535; | |
} | |
}, { | |
name: 'database', | |
required: true | |
}, { | |
name: 'charset', | |
required: true, | |
default: 'utf8' | |
}, { | |
name: 'username', | |
required: true | |
}, { | |
name: 'passwordMasked', | |
hidden: true, | |
replace: '*' | |
}, { | |
name: 'ssl', | |
message: 'Use ssl for connection?', | |
validator: /y[es]*|n[o]?/, | |
warning: 'Must respond yes or no', | |
default: 'yes' | |
}], function(err, result) { | |
console.log(' host: ' + result.host + ':' + result.port); | |
console.log(' database: ' + result.database); | |
console.log(' charset: ' + result.charset); | |
console.log(' username: ' + result.username); | |
console.log(' passwordMasked: ' + result.passwordMasked); | |
console.log(' use ssl: ' + result.ssl); | |
prompt.get([{ | |
name: 'yesno', | |
message: 'Is this input correct?', | |
validator: /y[es]*|n[o]?/, | |
warning: 'Must respond yes or no', | |
default: 'no' | |
}], function(err, result) { | |
if(result.yesno) { | |
accepted = true; | |
// write to config here | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment