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})`)}.`) }