diff --git a/bin/now b/bin/now index 4865503..1b9d449 100755 --- a/bin/now +++ b/bin/now @@ -1,27 +1,34 @@ #!/usr/bin/env node -import program from 'commander'; import Progress from 'progress'; import copy from '../lib/copy'; -import * as cfg from '../lib/cfg'; import { resolve } from 'path'; import login from '../lib/login'; +import * as cfg from '../lib/cfg'; +import { version } from '../../package'; import checkUpdate from '../lib/check-update'; import bytes from 'bytes'; import chalk from 'chalk'; +import minimist from 'minimist'; import Now from '../lib'; import ms from 'ms'; -program -.usage('[options]') -.version(require('../../package').version) -.option('-d, --debug', 'Debug mode [off]', false) -.option('-f, --force', 'Force a new deployment even if nothing has changed', false) -.option('-F, --forceSync', 'Force a new deployment even if nothing has changed and force syncing of all files', false) -.option('-L, --login', 'Configure login') -.option('-C, --no-clipboard', 'Do not attempt to copy URL to clipboard') -.parse(process.argv); +const argv = minimist(process.argv.slice(2)); +const help = () => { + console.log(` +𝚫 now [options] + +Options: -let path = program.args[program.args.length - 1]; + -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 + -C, --no-clipboard Do not attempt to copy URL to clipboard +`); +}; + +let path = argv._[0]; if (path) { if ('/' !== path[0]) { @@ -31,8 +38,14 @@ if (path) { path = process.cwd(); } -const debug = !!program.debug; -const clipboard = !program.noClipboard; +// options +const debug = argv.debug || argv.d; +const clipboard = !(argv.noClipboard || argv.C); +const force = argv.f || argv.force; +const forceSync = argv.F || argv.forceSync; +const shouldLogin = argv.L || argv.login; + +// auto-update checking const config = cfg.read(); const update = checkUpdate({ debug }); const exit = (code) => { @@ -42,10 +55,16 @@ const exit = (code) => { setTimeout(() => process.exit(code), 1000); }; -if (!config.token || program.login) { +if (argv.h || argv.help) { + help(); + exit(0); +} else if (argv.v || argv.version) { + console.log(chalk.bold('𝚫 now'), version); + exit(0); +} else if (!config.token || shouldLogin) { login() .then((token) => { - if (program.login) { + if (shouldLogin) { console.log('> Logged in successfully. Token saved in ~/.now.json'); exit(0); } else { @@ -74,7 +93,7 @@ async function sync (token) { const now = new Now(token, { debug }); try { - await now.create(path, { forceNew: program.force, forceSync: program.forceSync }); + await now.create(path, { forceNew: force, forceSync: forceSync }); } catch (err) { handleError(err); return; diff --git a/package.json b/package.json index 441af28..6ed4ac2 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "babel-runtime": "6.6.1", "bytes": "2.3.0", "chalk": "1.1.1", - "commander": "2.9.0", "copy-paste": "1.1.4", "fs-promise": "0.4.1", "graceful-fs": "4.1.3", @@ -26,7 +25,8 @@ "resumer": "0.0.0", "retry": "0.9.0", "spdy": "3.2.3", - "split-array": "1.0.1" + "split-array": "1.0.1", + "minimist": "1.2.0" }, "devDependencies": { "alpha-sort": "1.0.2",