From 1b01c6b4e1f846af01c0d6f9db662172e9af22f5 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Sat, 19 Apr 2014 17:08:41 -0700 Subject: [PATCH] introduce real argv parsing --- README.md | 8 ++++---- bin/lute.js | 22 ++++------------------ package.json | 3 ++- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 8726339..f3d8b99 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## Information - + @@ -28,13 +28,13 @@ Running 'lute' in a directory will serve that dir and set up LiveReload - no nee Serves current directory on default port (8080). Will find an open port if it's not available -`$ lute 3000` +`$ lute -p 3000` -Serves current directory on 3000, will find an open port if not available +`-p` option specifies a specific port. Executing this serves current directory on 3000, will find an open port if not available `$ lute open` -Serves current dir and opens in your browser +Serves current dir and opens in your browser ## TODO diff --git a/bin/lute.js b/bin/lute.js index 76d5140..bac8f2c 100755 --- a/bin/lute.js +++ b/bin/lute.js @@ -1,23 +1,9 @@ #!/usr/bin/env node +var argv = require('minimist')(process.argv.slice(2)); var isInt = require('../lib/util/isInt'); var serve = require('../lib/serve'); +var port = (argv.p && isInt(argv.p)) ? argv.p : 8080; -var cliArgs = process.argv.slice(2); -var port = isInt(cliArgs[0]) ? cliArgs[0] : 8080; - -// if a port or no args, start server - -if ( isInt(cliArgs[0]) || typeof cliArgs[0] === 'undefined') { - - // just start server & live reload - - serve(port); - -} - -if (cliArgs[0] === 'open') { - - serve(port, true); - -} \ No newline at end of file +// if a port or no args, start server +serve(port, (argv._.indexOf('open') !== -1)); diff --git a/package.json b/package.json index 7d745ec..4e0ccd2 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "express": "~3.4.7", "gulp-util": "~2.2.0", "portfinder": "~0.2.1", - "cheerio": "~0.13.1" + "cheerio": "~0.13.1", + "minimist": "0.0.8" }, "devDependencies": { "mocha": "*",
Packagelute