From b516ecccfaae1ac9a88a5f424506ceb2dedac35f Mon Sep 17 00:00:00 2001 From: Ahmed Abdel Razzak Date: Thu, 23 Jul 2015 00:57:01 +0200 Subject: [PATCH 1/2] Replace optimist with yargs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0149109..ea0a8f0 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "request": "2.11.4", - "optimist": "0.3.4", + "yargs": "3.15.0", "debug": "0.7.4", "openurl": "1.1.0" }, From 59d96a3cc63b49de7d35dde8e708cd6963397fc2 Mon Sep 17 00:00:00 2001 From: Ahmed Abdel Razzak Date: Thu, 23 Jul 2015 02:05:17 +0200 Subject: [PATCH 2/2] Update the client to include shorthand options Providing aliases for all of the supported options -h, --host -s, --subdomain -l, --local-host -o, --open -p, --port --help --version Minor clean up in the code removing the blocks that already handled by yargs ( version, help and required options ) Handle validating that the passed port could be validated as a number Remove the spaces in empty lines --- bin/client | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/bin/client b/bin/client index feb4ed2..d67e045 100755 --- a/bin/client +++ b/bin/client @@ -2,35 +2,37 @@ var lt_client = require('../client'); var open_url = require('openurl'); -var argv = require('optimist') - .usage('Usage: $0 --port [num]') - .options('host', { - default: 'http://localtunnel.me', - describe: 'upstream server providing forwarding' +var argv = require('yargs') + .usage('Usage: $0 --port [num] ') + .option('h', { + alias: 'host', + describe: 'Upstream server providing forwarding', + default: 'http://localtunnel.me' }) - .options('subdomain', { - describe: 'request this subdomain' + .option('s', { + alias: 'subdomain', + describe: 'Request this subdomain' }) - .options('local-host', { - describe: 'tunnel traffic to this host instead of localhost, override Host header to this host' + .option('l', { + alias: 'local-host', + describe: 'Tunnel traffic to this host instead of localhost, override Host header to this host' }) - .options('version', { - describe: 'print version and exit' - }) - .options('open', { + .options('o', { + alias: 'open', describe: 'opens url in your browser' }) - .describe('port', 'internal http server port') + .option('p', { + alias: 'port', + describe: 'Internal http server port', + }) + .require('port') + .help('help', 'Show this help and exit') + .version(require('../package').version) .argv; -if (argv.version) { - console.log(require('../package.json').version); - process.exit(0); -} - -if (argv.port == null) { - require('optimist').showHelp(); - console.error('Missing required arguments: port'); +if (typeof argv.port !== 'number') { + require('yargs').showHelp(); + console.error('port must be a number'); process.exit(1); } @@ -47,11 +49,11 @@ lt_client(opt.port, opt, function(err, tunnel) { } console.log('your url is: %s', tunnel.url); - + if (argv.open) { open_url.open(tunnel.url); } - + tunnel.on('error', function(err) { throw err; });