From c584f4279189aa76912e1fbf9b924f95d3e01709 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Fri, 6 Jan 2017 22:59:59 -0800 Subject: [PATCH] copy alias to clipboard & show message (#201) * copy alias to clipboard & show message * ensure status output if not ttys or cant copy --- lib/alias.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/alias.js b/lib/alias.js index 29c9034..7477713 100644 --- a/lib/alias.js +++ b/lib/alias.js @@ -1,14 +1,23 @@ // Packages import publicSuffixList from 'psl' +import minimist from 'minimist' import chalk from 'chalk' // Ours +import copy from './copy' import toHost from './to-host' import resolve4 from './dns' import isZeitWorld from './is-zeit-world' import {DOMAIN_VERIFICATION_ERROR} from './errors' import Now from './' +const argv = minimist(process.argv.slice(2), { + boolean: ['no-clipboard'], + alias: {'no-clipboard': 'C'} +}) + +const isTTY = process.stdout.isTTY +const clipboard = !argv['no-clipboard'] const domainRegex = /^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}$/ export default class Alias extends Now { @@ -234,7 +243,21 @@ export default class Alias extends Now { } const {created, uid} = newAlias if (created) { - console.log(`${chalk.cyan('> Success!')} Alias created ${chalk.dim(`(${uid})`)}: ${chalk.bold(chalk.underline(`https://${alias}`))} now points to ${chalk.bold(`https://${depl.url}`)} ${chalk.dim(`(${depl.uid})`)}`) + const pretty = `https://${alias}` + const output = `${chalk.cyan('> Success!')} Alias created ${chalk.dim(`(${uid})`)}: ${chalk.bold(chalk.underline(pretty))} now points to ${chalk.bold(`https://${depl.url}`)} ${chalk.dim(`(${depl.uid})`)}` + if (isTTY && clipboard) { + let append + try { + await copy(pretty) + append = '[copied to clipboard]' + } catch (err) { + append = '' + } finally { + console.log(`${output} ${append}`) + } + } else { + console.log(output) + } } else { console.log(`${chalk.cyan('> Success!')} Alias already exists ${chalk.dim(`(${uid})`)}.`) }