Browse Source

make `promptBool()` return false upon Ctrl+C (#557)

* move `prompt-options.js` to utils/input dir

* make `promptBool()` return false upon Ctrl+C

Also make the `info('Aborted')` output more consistent
across the CLI.

* Revert "handle user abort in `now domains buy` (#554)"

This reverts commit 34151c8193.
master
Nathan Rajlich 8 years ago
committed by Matheus Fernandes
parent
commit
23abd2a826
  1. 5
      bin/now-alias.js
  2. 3
      bin/now-billing.js
  3. 17
      bin/now-deploy.js
  4. 10
      bin/now-domains.js
  5. 2
      lib/alias.js
  6. 20
      lib/utils/input/prompt-bool.js
  7. 0
      lib/utils/input/prompt-options.js

5
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()

3
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()

17
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`)

10
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
}
}
break
}
default:

2
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) {

20
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
}

0
lib/utils/prompt-options.js → lib/utils/input/prompt-options.js

Loading…
Cancel
Save