|
|
@ -1,9 +1,6 @@ |
|
|
|
#!/usr/bin/env node |
|
|
|
|
|
|
|
import chalk from 'chalk'; |
|
|
|
import minimist from 'minimist'; |
|
|
|
// import chalk from 'chalk'; |
|
|
|
// import ms from 'ms'; |
|
|
|
// import table from 'text-table'; |
|
|
|
import NowAlias from '../lib/alias'; |
|
|
|
import login from '../lib/login'; |
|
|
|
import * as cfg from '../lib/cfg'; |
|
|
@ -15,77 +12,82 @@ const subcommand = argv._[0]; |
|
|
|
// options |
|
|
|
const help = () => { |
|
|
|
console.log(` |
|
|
|
𝚫 now alias <ls | set | rm> <now_url> <alias> [≤alias2>[, <alias3>]] |
|
|
|
|
|
|
|
Alias: ln |
|
|
|
${chalk.bold('𝚫 now alias')} <ls | set | rm> <deployment> <alias> |
|
|
|
|
|
|
|
Options: |
|
|
|
${chalk.dim('Options:')} |
|
|
|
|
|
|
|
-h, --help output usage information |
|
|
|
-d, --debug Debug mode [off] |
|
|
|
-d, --debug debug mode [off] |
|
|
|
|
|
|
|
Examples: |
|
|
|
Lists all the aliases you have configured: |
|
|
|
${chalk.dim('Examples:')} |
|
|
|
|
|
|
|
$ now alias ls |
|
|
|
Lists all your aliases: |
|
|
|
|
|
|
|
${chalk.cyan('$ now alias ls')} |
|
|
|
|
|
|
|
Adds a particular alias to my-api.now.sh: |
|
|
|
$ now alias set api-ownv3nc9f8.now.sh my-api.now.sh |
|
|
|
|
|
|
|
${chalk.cyan(`$ now alias set ${chalk.underline('api-ownv3nc9f8.now.sh')} ${chalk.underline('my-api.now.sh')}`)} |
|
|
|
|
|
|
|
The \`.now.sh\` suffix can be ommited: |
|
|
|
|
|
|
|
$ now alias set api-ownv3nc9f8 my-api |
|
|
|
${chalk.cyan('$ now alias set api-ownv3nc9f8 my-api')} |
|
|
|
|
|
|
|
The deployment id can be used as the source: |
|
|
|
|
|
|
|
$ now alias set deploymentId my-alias |
|
|
|
${chalk.cyan('$ now alias set deploymentId my-alias')} |
|
|
|
|
|
|
|
Custom domains work as well. They will ask you for your email |
|
|
|
address as we dynamically provision a certificate: |
|
|
|
|
|
|
|
$ now alias set api-ownv3nc9f8.now.sh my-api.com |
|
|
|
${chalk.cyan(`$ now alias set ${chalk.underline('api-ownv3nc9f8.now.sh')} ${chalk.underline('my-api.com')}`)} |
|
|
|
|
|
|
|
You can optionally put \`http://\` or \`https://\` in front of the |
|
|
|
You can optionally put ${chalk.dim('`http://`')} or ${chalk.dim('`https://`')} in front of the |
|
|
|
parameters and they will be ignored. |
|
|
|
|
|
|
|
Removing an alias: |
|
|
|
$ now alias rm aliasId |
|
|
|
|
|
|
|
${chalk.cyan('$ now alias rm aliasId')} |
|
|
|
|
|
|
|
To get the list of alias ids, use \`now alias ls\`. |
|
|
|
|
|
|
|
${chalk.dim('Alias:')} ln |
|
|
|
`); |
|
|
|
}; |
|
|
|
|
|
|
|
if (argv.h || argv.help) { |
|
|
|
help(); |
|
|
|
process.exit(0); |
|
|
|
} |
|
|
|
const exit = (code) => { |
|
|
|
// we give stdout some time to flush out |
|
|
|
// because there's a node bug where |
|
|
|
// stdout writes are asynchronous |
|
|
|
// https://github.com/nodejs/node/issues/6456 |
|
|
|
setTimeout(() => process.exit(code || 0), 100); |
|
|
|
}; |
|
|
|
|
|
|
|
if (!subcommand) { |
|
|
|
error('No subcommand specified'); |
|
|
|
if (argv.h || argv.help || !subcommand) { |
|
|
|
help(); |
|
|
|
process.exit(1); |
|
|
|
exit(0); |
|
|
|
} else { |
|
|
|
// options |
|
|
|
const debug = argv.debug || argv.d; |
|
|
|
const apiUrl = argv.url || 'https://api.zeit.co'; |
|
|
|
|
|
|
|
const config = cfg.read(); |
|
|
|
|
|
|
|
Promise.resolve(config.token || login(apiUrl)) |
|
|
|
.then(async (token) => { |
|
|
|
try { |
|
|
|
await run(token); |
|
|
|
} catch (err) { |
|
|
|
error(`Unknown error: ${err.stack}`); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch((e) => { |
|
|
|
error(`Authentication error – ${e.message}`); |
|
|
|
exit(1); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// options |
|
|
|
const debug = argv.debug || argv.d; |
|
|
|
const apiUrl = argv.url || 'https://api.zeit.co'; |
|
|
|
|
|
|
|
const config = cfg.read(); |
|
|
|
|
|
|
|
Promise.resolve(config.token || login(apiUrl)) |
|
|
|
.then(async (token) => { |
|
|
|
try { |
|
|
|
await run(token); |
|
|
|
} catch (err) { |
|
|
|
error(`Unknown error: ${err.stack}`); |
|
|
|
process.exit(1); |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch((e) => { |
|
|
|
error(`Authentication error – ${e.message}`); |
|
|
|
process.exit(1); |
|
|
|
}); |
|
|
|
|
|
|
|
function getArgs (args) { |
|
|
|
return { url: args[1], aliases: args.slice(2) }; |
|
|
|
} |
|
|
@ -98,7 +100,7 @@ async function run (token) { |
|
|
|
if (!url) { |
|
|
|
error('No deployment url specified. You can see active deployments with `now ls`.'); |
|
|
|
help(); |
|
|
|
process.exit(1); |
|
|
|
return exit(1); |
|
|
|
} else if (!aliases.length) { |
|
|
|
error('No alias url specified. This is the URL your deployment will be tied to.'); |
|
|
|
} |
|
|
@ -117,6 +119,6 @@ async function run (token) { |
|
|
|
default: |
|
|
|
error('Invalid subcommand'); |
|
|
|
help(); |
|
|
|
process.exit(); |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|