From 033d63057cdf1645681f6746b1ba2a65c139254d Mon Sep 17 00:00:00 2001 From: Alex Warren Date: Sun, 19 Oct 2014 15:25:07 +0100 Subject: [PATCH] Use yargs to parse options --- package.json | 5 +++-- squiffy.js | 45 +++++++++++++++++++++------------------------ 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index c920862..27270ca 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "squiffy", - "version": "2.0.1", + "version": "2.1.0", "description": "A tool for creating multiple-choice interactive stories", "dependencies": { "finalhandler": "^0.3.1", "glob": "^4.0.6", "marked": "^0.3.2", "serve-static": "^1.7.0", - "underscore": "^1.7.0" + "underscore": "^1.7.0", + "yargs": "^1.3.2" }, "author": "Alex Warren ", "repository": { diff --git a/squiffy.js b/squiffy.js index 04f4bab..f5e44cd 100644 --- a/squiffy.js +++ b/squiffy.js @@ -21,7 +21,7 @@ String.prototype.endsWith = function(suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1; }; -var squiffyVersion = "2.0"; +var squiffyVersion = "2.1"; function Compiler() { this.process = function(inputFilename, sourcePath, options) { @@ -497,29 +497,26 @@ function startServer(dir) { server.listen(8282); } -function getOptions() { - return { - useCdn: _.contains(process.argv, "-c"), - serve: _.contains(process.argv, "-s"), - }; -} - console.log("Squiffy " + squiffyVersion); -if (process.argv.length < 3) { - console.log("Syntax: input.squiffy [-c]"); - console.log("Options:"); - console.log(" -c Use CDN for jQuery"); - console.log(" -s Start HTTP server after compiling") - console.log("\nFor help, see http://docs.textadventures.co.uk/squiffy/") -} -else { - var options = getOptions(); - var compiler = new Compiler(); - var result = compiler.process(process.argv[2], __dirname, options); - - if (result && options.serve) { - startServer(result); - console.log("Started http://localhost:8282/"); - } +var argv = require('yargs') + .usage("Compiles a Squiffy script file into HTML and JavaScript.\nFor help, see http://docs.textadventures.co.uk/squiffy/\nUsage: $0 filename.squiffy [options]") + .demand(1) + .alias("c", "cdn") + .alias("s", "serve") + .describe("c", "Use CDN for jQuery") + .describe("s", "Start HTTP server after compiling") + .argv; + +var options = { + useCdn: argv.c, + serve: argv.s, +}; + +var compiler = new Compiler(); +var result = compiler.process(argv._[0], __dirname, options); + +if (result && options.serve) { + startServer(result); + console.log("Started http://localhost:8282/"); } \ No newline at end of file