diff --git a/bin/now-remove b/bin/now-remove index 3f9495d..a0422de 100755 --- a/bin/now-remove +++ b/bin/now-remove @@ -55,13 +55,13 @@ function readConfirmation (app) { return new Promise((resolve, reject) => { const time = chalk.gray(ms(new Date() - app.created) + ' ago'); const tbl = table( - [[app.uid, time, `https://${app.url}`]], + [[app.uid, `https://${app.url}`, time]], { align: ['l', 'r', 'l'], hsep: ' '.repeat(6) } ); process.stdout.write('> The following deployment will be removed permanently\n'); process.stdout.write(' ' + tbl + '\n'); - process.stdout.write(` ${chalk.bold.red('> Are you sure?')} ${chalk.gray('[yN] ')}`); + process.stdout.write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[yN] ')}`); process.stdin.on('data', (d) => { process.stdin.pause(); diff --git a/lib/alias.js b/lib/alias.js index 8ae7d93..fd00ce2 100644 --- a/lib/alias.js +++ b/lib/alias.js @@ -3,6 +3,8 @@ import dns from 'dns'; import Now from '../lib'; import toHost from './to-host'; import chalk from 'chalk'; +import table from 'text-table'; +import ms from 'ms'; export default class Alias extends Now { @@ -37,22 +39,26 @@ export default class Alias extends Now { throw err; } - return this.retry(async (bail, attempt) => { - const res = await this._fetch(`/now/aliases/${_alias.uid}`, { - method: 'DELETE' - }); + if (await readConfirmation(_alias)) { + return this.retry(async (bail, attempt) => { + const res = await this._fetch(`/now/aliases/${_alias.uid}`, { + method: 'DELETE' + }); - if (403 === res.status) { - return bail(new Error('Unauthorized')); - } + if (403 === res.status) { + return bail(new Error('Unauthorized')); + } - if (res.status !== 200) { - const err = new Error('Deletion failed. Try again later.'); - throw err; - } + if (res.status !== 200) { + const err = new Error('Deletion failed. Try again later.'); + throw err; + } - console.log(`${chalk.cyan('> Success!')}`); - }); + console.log(`${chalk.cyan('> Success!')} The alias has been removed.`); + }); + } else { + console.log('> Aborted'); + } } async findAlias (alias) { @@ -271,3 +277,23 @@ function resolve4 (host) { }); }); } + +function readConfirmation (alias) { + return new Promise((resolve, reject) => { + const time = chalk.gray(ms(new Date() - new Date(alias.created)) + ' ago'); + const tbl = table( + [[alias.uid, `https://${alias.alias}`, time]], + { align: ['l', 'r', 'l'], hsep: ' '.repeat(3) } + ); + + process.stdout.write('> The following alias will be removed permanently\n'); + process.stdout.write(' ' + tbl + '\n'); + process.stdout.write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[yN] ')}`); + + process.stdin.on('data', (d) => { + process.stdin.pause(); + process.stdin.write('\n'); + resolve('y' === d.toString().trim()); + }).resume(); + }); +}