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
This commit is contained in:
Ahmed Abdel Razzak
2015-07-23 02:05:17 +02:00
parent b516ecccfa
commit 59d96a3cc6

View File

@@ -2,35 +2,37 @@
var lt_client = require('../client'); var lt_client = require('../client');
var open_url = require('openurl'); var open_url = require('openurl');
var argv = require('optimist') var argv = require('yargs')
.usage('Usage: $0 --port [num]') .usage('Usage: $0 --port [num] <options>')
.options('host', { .option('h', {
default: 'http://localtunnel.me', alias: 'host',
describe: 'upstream server providing forwarding' describe: 'Upstream server providing forwarding',
default: 'http://localtunnel.me'
}) })
.options('subdomain', { .option('s', {
describe: 'request this subdomain' alias: 'subdomain',
describe: 'Request this subdomain'
}) })
.options('local-host', { .option('l', {
describe: 'tunnel traffic to this host instead of localhost, override Host header to this host' alias: 'local-host',
describe: 'Tunnel traffic to this host instead of localhost, override Host header to this host'
}) })
.options('version', { .options('o', {
describe: 'print version and exit' alias: 'open',
})
.options('open', {
describe: 'opens url in your browser' 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; .argv;
if (argv.version) { if (typeof argv.port !== 'number') {
console.log(require('../package.json').version); require('yargs').showHelp();
process.exit(0); console.error('port must be a number');
}
if (argv.port == null) {
require('optimist').showHelp();
console.error('Missing required arguments: port');
process.exit(1); process.exit(1);
} }
@@ -47,11 +49,11 @@ lt_client(opt.port, opt, function(err, tunnel) {
} }
console.log('your url is: %s', tunnel.url); console.log('your url is: %s', tunnel.url);
if (argv.open) { if (argv.open) {
open_url.open(tunnel.url); open_url.open(tunnel.url);
} }
tunnel.on('error', function(err) { tunnel.on('error', function(err) {
throw err; throw err;
}); });