diff --git a/bin/now-alias.js b/bin/now-alias.js index 21b64cc..352af87 100755 --- a/bin/now-alias.js +++ b/bin/now-alias.js @@ -19,6 +19,7 @@ const { error } = require('../lib/error') const toHost = require('../lib/to-host') const { reAlias } = require('../lib/re-alias') const exit = require('../lib/utils/exit') +const info = require('../lib/utils/output/info') const logo = require('../lib/utils/output/logo') const promptBool = require('../lib/utils/input/prompt-bool') @@ -304,8 +305,8 @@ async function run({ token, config: { currentTeam, user } }) { try { const confirmation = await confirmDeploymentRemoval(alias, _alias) if (!confirmation) { - console.log('\n> Aborted') - process.exit(0) + info('Aborted') + return process.exit(0) } const start = new Date() diff --git a/bin/now-billing.js b/bin/now-billing.js index 13b3c43..0454481 100644 --- a/bin/now-billing.js +++ b/bin/now-billing.js @@ -17,6 +17,7 @@ const indent = require('../lib/indent') const listInput = require('../lib/utils/input/list') const success = require('../lib/utils/output/success') const promptBool = require('../lib/utils/input/prompt-bool') +const info = require('../lib/utils/output/info') const logo = require('../lib/utils/output/logo') const argv = minimist(process.argv.slice(2), { @@ -236,7 +237,7 @@ async function run({ token, config: { currentTeam, user } }) { trailing: '\n' }) if (!confirmation) { - console.log('Aborted') + info('Aborted') break } const start = new Date() diff --git a/bin/now-deploy.js b/bin/now-deploy.js index abd66ff..116fd9c 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -22,7 +22,6 @@ const { version } = require('../lib/pkg') const Logger = require('../lib/build-logger') const Now = require('../lib') const toHumanPath = require('../lib/utils/to-human-path') -const promptOptions = require('../lib/utils/prompt-options') const { handleError, error } = require('../lib/error') const { fromGit, isRepoPath, gitPathParts } = require('../lib/git') const readMetaData = require('../lib/read-metadata') @@ -35,6 +34,7 @@ const info = require('../lib/utils/output/info') const wait = require('../lib/utils/output/wait') const NowPlans = require('../lib/plans') const promptBool = require('../lib/utils/input/prompt-bool') +const promptOptions = require('../lib/utils/input/prompt-options') const note = require('../lib/utils/output/note') const argv = minimist(process.argv.slice(2), { @@ -550,17 +550,10 @@ async function sync({ token, config: { currentTeam, user } }) { `${chalk.bold((currentTeam && `${currentTeam.slug} is`) || `You (${user.username || user.email}) are`)} on the OSS plan. Your code and logs will be made ${chalk.bold('public')}.` ) - let proceed - try { - const label = 'Are you sure you want to proceed with the deployment?' - proceed = await promptBool(label, { trailing: eraseLines(1) }) - } catch (err) { - if (err.message === 'USER_ABORT') { - proceed = false - } else { - throw err - } - } + const proceed = await promptBool( + 'Are you sure you want to proceed with the deployment?', + { trailing: eraseLines(1) } + ) if (proceed) { note(`You can use ${cmd('now --public')} to skip this prompt`) diff --git a/bin/now-domains.js b/bin/now-domains.js index 429d0e7..a4def98 100755 --- a/bin/now-domains.js +++ b/bin/now-domains.js @@ -272,22 +272,12 @@ async function run({ token, config: { currentTeam, user } }) { break } case 'buy': { - try { - await require(resolve(__dirname, 'domains', 'buy.js'))({ - domains: domain, - args, - currentTeam, - user - }) - } catch (err) { - if (err.message === 'USER_ABORT') { - // Move the prompt to a newline before exiting - console.log() - process.exit(1) - } else { - throw err - } - } + await require(resolve(__dirname, 'domains', 'buy.js'))({ + domains: domain, + args, + currentTeam, + user + }) break } default: diff --git a/lib/alias.js b/lib/alias.js index b964a8f..63c64a1 100644 --- a/lib/alias.js +++ b/lib/alias.js @@ -255,7 +255,7 @@ module.exports = class Alias extends Now { }) if (!confirmation) { - console.log('\n> Aborted') + info('Aborted') return exit(1) } } catch (err) { diff --git a/lib/utils/input/prompt-bool.js b/lib/utils/input/prompt-bool.js index dda1b5a..31e979d 100644 --- a/lib/utils/input/prompt-bool.js +++ b/lib/utils/input/prompt-bool.js @@ -13,8 +13,8 @@ module.exports = ( trailing = '' } = {} ) => { - return new Promise((resolve, reject) => { - const isRaw = process.stdin.isRaw + return new Promise(resolve => { + const isRaw = stdin.isRaw stdin.setRawMode(true) stdin.resume() @@ -29,20 +29,18 @@ module.exports = ( function onData(buffer) { const data = buffer.toString() - if (abortSequences.has(data)) { - restore() - return reject(new Error('USER_ABORT')) - } - - if (resolveChars.has(data[0])) { - restore() - resolve(defaultValue) - } else if (data[0].toLowerCase() === yesChar) { + if (data[0].toLowerCase() === yesChar) { restore() resolve(true) } else if (data[0].toLowerCase() === noChar) { restore() resolve(false) + } else if (abortSequences.has(data)) { + restore() + resolve(false) + } else if (resolveChars.has(data[0])) { + restore() + resolve(defaultValue) } else { // ignore extraneous input } diff --git a/lib/utils/prompt-options.js b/lib/utils/input/prompt-options.js similarity index 100% rename from lib/utils/prompt-options.js rename to lib/utils/input/prompt-options.js