Browse Source

now-alias: clean up docs and fix node bug with early exit

master
Guillermo Rauch 9 years ago
parent
commit
a2855c178e
  1. 96
      bin/now-alias

96
bin/now-alias

@ -1,9 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
import chalk from 'chalk';
import minimist from 'minimist'; import minimist from 'minimist';
// import chalk from 'chalk';
// import ms from 'ms';
// import table from 'text-table';
import NowAlias from '../lib/alias'; import NowAlias from '../lib/alias';
import login from '../lib/login'; import login from '../lib/login';
import * as cfg from '../lib/cfg'; import * as cfg from '../lib/cfg';
@ -15,77 +12,82 @@ const subcommand = argv._[0];
// options // options
const help = () => { const help = () => {
console.log(` console.log(`
𝚫 now alias <ls | set | rm> <now_url> <alias> [≤alias2>[, <alias3>]] ${chalk.bold('𝚫 now alias')} <ls | set | rm> <deployment> <alias>
Alias: ln
Options: ${chalk.dim('Options:')}
-h, --help output usage information -h, --help output usage information
-d, --debug Debug mode [off] -d, --debug debug mode [off]
Examples: ${chalk.dim('Examples:')}
Lists all the aliases you have configured:
$ now alias ls Lists all your aliases:
${chalk.cyan('$ now alias ls')}
Adds a particular alias to my-api.now.sh: 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: 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: 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 Custom domains work as well. They will ask you for your email
address as we dynamically provision a certificate: 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. parameters and they will be ignored.
Removing an alias: Removing an alias:
$ now alias rm aliasId
${chalk.cyan('$ now alias rm aliasId')}
To get the list of alias ids, use \`now alias ls\`. To get the list of alias ids, use \`now alias ls\`.
${chalk.dim('Alias:')} ln
`); `);
}; };
if (argv.h || argv.help) { const exit = (code) => {
help(); // we give stdout some time to flush out
process.exit(0); // 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) { if (argv.h || argv.help || !subcommand) {
error('No subcommand specified');
help(); 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) { function getArgs (args) {
return { url: args[1], aliases: args.slice(2) }; return { url: args[1], aliases: args.slice(2) };
} }
@ -98,7 +100,7 @@ async function run (token) {
if (!url) { if (!url) {
error('No deployment url specified. You can see active deployments with `now ls`.'); error('No deployment url specified. You can see active deployments with `now ls`.');
help(); help();
process.exit(1); return exit(1);
} else if (!aliases.length) { } else if (!aliases.length) {
error('No alias url specified. This is the URL your deployment will be tied to.'); error('No alias url specified. This is the URL your deployment will be tied to.');
} }
@ -117,6 +119,6 @@ async function run (token) {
default: default:
error('Invalid subcommand'); error('Invalid subcommand');
help(); help();
process.exit(); exit(0);
} }
} }

Loading…
Cancel
Save