Skip to content

Commit

Permalink
Use yargs to parse options
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwarren committed Oct 19, 2014
1 parent 88973fa commit 033d630
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"repository": {
Expand Down
45 changes: 21 additions & 24 deletions squiffy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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/");
}

0 comments on commit 033d630

Please sign in to comment.