2021-02-26 14:30:24 +01:00
|
|
|
const inquirer = require("inquirer")
|
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
exports.confirmation = async question => {
|
2021-02-26 14:30:24 +01:00
|
|
|
const config = {
|
|
|
|
type: "confirm",
|
|
|
|
message: question,
|
|
|
|
default: true,
|
|
|
|
name: "confirmation",
|
|
|
|
}
|
|
|
|
return (await inquirer.prompt(config)).confirmation
|
|
|
|
}
|
2021-02-26 14:48:11 +01:00
|
|
|
|
|
|
|
exports.string = async (question, defaultString = null) => {
|
|
|
|
const config = {
|
|
|
|
type: "input",
|
|
|
|
name: "string",
|
|
|
|
message: question,
|
|
|
|
}
|
|
|
|
if (defaultString) {
|
|
|
|
config.default = defaultString
|
|
|
|
}
|
|
|
|
return (await inquirer.prompt(config)).string
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.number = async (question, defaultNumber) => {
|
|
|
|
const config = {
|
|
|
|
type: "input",
|
2021-02-26 18:09:20 +01:00
|
|
|
name: "number",
|
2021-02-26 14:48:11 +01:00
|
|
|
message: question,
|
2021-05-04 12:32:22 +02:00
|
|
|
validate: value => {
|
2021-02-26 14:48:11 +01:00
|
|
|
let valid = !isNaN(parseFloat(value))
|
|
|
|
return valid || "Please enter a number"
|
|
|
|
},
|
|
|
|
filter: Number,
|
|
|
|
}
|
|
|
|
if (defaultNumber) {
|
|
|
|
config.default = defaultNumber
|
|
|
|
}
|
|
|
|
return (await inquirer.prompt(config)).number
|
|
|
|
}
|