for each key that has an empty value, no matter it's a pre-defined key in the script or a specified key in command line, ask the user to enter a value
interactively
This commit is contained in:
@@ -39,7 +39,9 @@ const existingEnv = fs.existsSync('./env_loc.gitomit.sfomit.json') ? require(pat
|
||||
|
||||
const baseEnv = Object.assign({}, paramDefaults, defaultEnv, existingEnv)
|
||||
|
||||
const askParamValues = (keys) =>
|
||||
const isEmptyValue = (value) => value === '' || value === undefined || value === null
|
||||
|
||||
const askKeyValues = (keys) =>
|
||||
new Promise((resolve) => {
|
||||
if (!keys.length || !process.stdin.isTTY) {
|
||||
resolve({})
|
||||
@@ -61,7 +63,7 @@ const askParamValues = (keys) =>
|
||||
}
|
||||
|
||||
const key = keys[index]
|
||||
rl.question(`Input value for "${key}" (Enter for empty): `, (answer) => {
|
||||
rl.question(`Input value for "${key}" (Enter to keep empty): `, (answer) => {
|
||||
values[key] = answer === '' ? '' : answer
|
||||
index += 1
|
||||
askNext()
|
||||
@@ -72,7 +74,8 @@ const askParamValues = (keys) =>
|
||||
})
|
||||
|
||||
const main = async () => {
|
||||
const inputValues = await askParamValues(params)
|
||||
const keysToPrompt = Object.keys(baseEnv).filter((key) => isEmptyValue(baseEnv[key]))
|
||||
const inputValues = await askKeyValues(keysToPrompt)
|
||||
const localEnv = Object.assign({}, baseEnv, inputValues)
|
||||
|
||||
fs.writeFileSync(path.resolve('./env_loc.gitomit.sfomit.json'), JSON.stringify(localEnv, null, 2), 'utf8')
|
||||
|
||||
Reference in New Issue
Block a user