budibase/packages/cli/src/questions.js

41 lines
906 B
JavaScript
Raw Normal View History

2021-02-26 14:30:24 +01:00
const inquirer = require("inquirer")
2021-05-03 09:31:09 +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
}
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",
message: question,
2021-05-03 09:31:09 +02:00
validate: (value) => {
let valid = !isNaN(parseFloat(value))
return valid || "Please enter a number"
},
filter: Number,
}
if (defaultNumber) {
config.default = defaultNumber
}
return (await inquirer.prompt(config)).number
}