diff --git a/bin/now-alias b/bin/now-alias index d2e4755..014dd81 100755 --- a/bin/now-alias +++ b/bin/now-alias @@ -10,10 +10,13 @@ import { error } from '../lib/error'; import toHost from '../lib/to-host'; const argv = minimist(process.argv.slice(2), { + string: ['config', 'token'], boolean: ['help', 'debug'], alias: { help: 'h', - debug: 'd' + config: 'c', + debug: 'd', + token: 't' } }); const subcommand = argv._[0]; @@ -25,8 +28,10 @@ const help = () => { ${chalk.dim('Options:')} - -h, --help output usage information - -d, --debug debug mode [off] + -h, --help output usage information + -c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file + -d, --debug debug mode [off] + -t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token ${chalk.dim('Examples:')} @@ -66,6 +71,7 @@ const help = () => { // options const debug = argv.debug; const apiUrl = argv.url || 'https://api.zeit.co'; +if (argv.config) cfg.setConfigFile(argv.config); const exit = (code) => { // we give stdout some time to flush out @@ -81,7 +87,7 @@ if (argv.help || !subcommand) { } else { const config = cfg.read(); - Promise.resolve(config.token || login(apiUrl)) + Promise.resolve(argv.token || config.token || login(apiUrl)) .then(async (token) => { try { await run(token); diff --git a/bin/now-deploy b/bin/now-deploy index ed03c06..963c610 100755 --- a/bin/now-deploy +++ b/bin/now-deploy @@ -17,12 +17,15 @@ import ms from 'ms'; import { handleError, error } from '../lib/error'; const argv = minimist(process.argv.slice(2), { + string: ['config', 'token'], boolean: ['help', 'version', 'debug', 'force', 'login', 'no-clipboard', 'forward-npm', 'docker', 'npm'], alias: { help: 'h', + config: 'c', debug: 'd', version: 'v', force: 'f', + token: 't', forceSync: 'F', login: 'L', public: 'p', @@ -47,14 +50,16 @@ const help = () => { ${chalk.dim('Options:')} - -h, --help output usage information - -v, --version output the version number - -d, --debug debug mode [off] - -f, --force force a new deployment even if nothing has changed - -L, --login configure login - -p, --public deployment is public (\`/_src\` is exposed) [on for oss, off for premium] - -C, --no-clipboard do not attempt to copy URL to clipboard - -N, --forward-npm Forward login information to install private NPM modules + -h, --help output usage information + -v, --version output the version number + -c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file + -d, --debug debug mode [off] + -f, --force force a new deployment even if nothing has changed + -t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token + -L, --login configure login + -p, --public deployment is public (\`/_src\` is exposed) [on for oss, off for premium] + -C, --no-clipboard do not attempt to copy URL to clipboard + -N, --forward-npm Forward login information to install private NPM modules ${chalk.dim('Examples:')} @@ -109,6 +114,7 @@ const wantsPublic = argv.public; const apiUrl = argv.url || 'https://api.zeit.co'; const isTTY = process.stdout.isTTY; const quiet = !isTTY; +if (argv.config) cfg.setConfigFile(argv.config); const config = cfg.read(); const alwaysForwardNpm = config.forwardNpm; @@ -118,7 +124,7 @@ if (argv.h || argv.help) { } else if (argv.v || argv.version) { console.log(chalk.bold('𝚫 now'), version); process.exit(0); -} else if (!config.token || shouldLogin) { +} else if (!(argv.token || config.token) || shouldLogin) { login(apiUrl) .then((token) => { if (shouldLogin) { @@ -136,7 +142,7 @@ if (argv.h || argv.help) { process.exit(1); }); } else { - sync(config.token).catch((err) => { + sync(argv.token || config.token).catch((err) => { error(`Unknown error: ${err.stack}`); process.exit(1); }); diff --git a/bin/now-domains b/bin/now-domains index d69de4d..da34ea8 100755 --- a/bin/now-domains +++ b/bin/now-domains @@ -10,10 +10,13 @@ import toHost from '../lib/to-host'; import NowDomains from '../lib/domains'; const argv = minimist(process.argv.slice(2), { + string: ['config', 'token'], boolean: ['help', 'debug'], alias: { help: 'h', - debug: 'd' + config: 'c', + debug: 'd', + token: 't' } }); const subcommand = argv._[0]; @@ -25,8 +28,10 @@ const help = () => { ${chalk.dim('Options:')} - -h, --help output usage information - -d, --debug debug mode [off] + -h, --help output usage information + -c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file + -d, --debug debug mode [off] + -t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token ${chalk.dim('Examples:')} @@ -71,6 +76,7 @@ const help = () => { // options const debug = argv.debug; const apiUrl = argv.url || 'https://api.zeit.co'; +if (argv.config) cfg.setConfigFile(argv.config); const exit = (code) => { // we give stdout some time to flush out @@ -86,7 +92,7 @@ if (argv.help || !subcommand) { } else { const config = cfg.read(); - Promise.resolve(config.token || login(apiUrl)) + Promise.resolve(argv.token || config.token || login(apiUrl)) .then(async (token) => { try { await run(token); diff --git a/bin/now-list b/bin/now-list index 72c62da..134d043 100755 --- a/bin/now-list +++ b/bin/now-list @@ -11,10 +11,13 @@ import * as cfg from '../lib/cfg'; import { handleError, error } from '../lib/error'; const argv = minimist(process.argv.slice(2), { + string: ['config', 'token'], boolean: ['help', 'debug'], alias: { help: 'h', - debug: 'd' + config: 'c', + debug: 'd', + token: 't' } }); @@ -24,8 +27,10 @@ const help = () => { ${chalk.dim('Options:')} - -h, --help output usage information - -d, --debug debug mode [off] + -h, --help output usage information + -c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file + -d, --debug debug mode [off] + -t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token ${chalk.dim('Examples:')} @@ -51,10 +56,10 @@ const app = argv._[0]; // options const debug = argv.debug; const apiUrl = argv.url || 'https://api.zeit.co'; - +if (argv.config) cfg.setConfigFile(argv.config); const config = cfg.read(); -Promise.resolve(config.token || login(apiUrl)) +Promise.resolve(argv.token || config.token || login(apiUrl)) .then(async (token) => { try { await list(token); diff --git a/bin/now-remove b/bin/now-remove index 230718d..b5ab69a 100755 --- a/bin/now-remove +++ b/bin/now-remove @@ -10,10 +10,13 @@ import * as cfg from '../lib/cfg'; import { handleError, error } from '../lib/error'; const argv = minimist(process.argv.slice(2), { + string: ['config', 'token'], boolean: ['help', 'debug', 'hard'], alias: { help: 'h', - debug: 'd' + config: 'c', + debug: 'd', + token: 't' } }); @@ -26,8 +29,10 @@ const help = () => { ${chalk.dim('Options:')} - -h, --help output usage information - -d, --debug debug mode [off] + -h, --help output usage information + -c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file + -d, --debug debug mode [off] + -t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token ${chalk.dim('Examples:')} @@ -48,7 +53,7 @@ if (argv.help || !deploymentId) { const debug = argv.debug; const apiUrl = argv.url || 'https://api.zeit.co'; const hard = argv.hard || false; - +if (argv.config) cfg.setConfigFile(argv.config); const config = cfg.read(); function readConfirmation (depl, aliases) { @@ -77,7 +82,7 @@ function readConfirmation (depl, aliases) { }); } -Promise.resolve(config.token || login(apiUrl)) +Promise.resolve(argv.token || config.token || login(apiUrl)) .then(async (token) => { try { await remove(token); diff --git a/bin/now-secrets b/bin/now-secrets index 33924df..f2dedb9 100755 --- a/bin/now-secrets +++ b/bin/now-secrets @@ -8,11 +8,14 @@ import NowSecrets from '../lib/secrets'; import ms from 'ms'; const argv = minimist(process.argv.slice(2), { + string: ['config', 'token'], boolean: ['help', 'debug', 'base64'], alias: { help: 'h', + config: 'c', debug: 'd', - base64: 'b' + base64: 'b', + token: 't' } }); const subcommand = argv._[0]; @@ -24,9 +27,11 @@ const help = () => { ${chalk.dim('Options:')} - -h, --help output usage information - -b, --base64 treat value as base64-encoded - -d, --debug debug mode [off] + -h, --help output usage information + -b, --base64 treat value as base64-encoded + -c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file + -d, --debug debug mode [off] + -t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token ${chalk.dim('Examples:')} @@ -61,6 +66,7 @@ const help = () => { // options const debug = argv.debug; const apiUrl = argv.url || 'https://api.zeit.co'; +if (argv.config) cfg.setConfigFile(argv.config); const exit = (code) => { // we give stdout some time to flush out @@ -76,7 +82,7 @@ if (argv.help || !subcommand) { } else { const config = cfg.read(); - Promise.resolve(config.token || login(apiUrl)) + Promise.resolve(argv.token || config.token || login(apiUrl)) .then(async (token) => { try { await run(token); diff --git a/lib/cfg.js b/lib/cfg.js index 5124948..5393065 100644 --- a/lib/cfg.js +++ b/lib/cfg.js @@ -2,7 +2,11 @@ import path from 'path'; import fs from 'fs-promise'; import { homedir } from 'os'; -const file = path.resolve(homedir(), '.now.json'); +let file = process.env.NOW_JSON ? path.resolve(process.env.NOW_JSON) : path.resolve(homedir(), '.now.json'); + +export function setConfigFile (nowjson) { + file = path.resolve(nowjson); +} export function read () { let existing = null;