Skip to content

Commit

Permalink
Add a basic command line interface. #7
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-wang committed Feb 24, 2014
1 parent e8f7d79 commit d93e9d7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
44 changes: 42 additions & 2 deletions commonJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,46 @@ if (typeof require !== "undefined" && typeof exports !== "undefined") {
return TeXZilla.toMathML.apply(TeXZilla, arguments);
};

/* FIXME: add some commonJS command line API.
https://github.com/fred-wang/TeXZilla/issues/7 */
/* Command line API */
var system = require("system");
var args = system.args;

function usage(aName) {
console.log("\nUsage:\n");
console.log("slimerjs " + aName + " [help]");
console.log(" Print this help message.\n");
console.log("slimerjs " + aName + " parser aTeX [aDisplay] [aRTL] [aThrowExceptionOnError]");
console.log(" Print TeXZilla.toMathMLString(aTeX, aDisplay, aRTL, aThrowExceptionOnError)");
console.log(" The interpretation of arguments and the default values are the same.\n");
console.log("slimerjs " + aName + " webserver [port]");
console.log(" TODO\n");
console.log("cat input | slimerjs " + aName + " stream > output");
console.log(" TODO\n");
}

if (args.length >= 3 && args[1] === "parser") {
var tex = args[2];
var display = (args.length >= 4 ? args[3] === "true" : false);
var RTL = (args.length >= 5 ? args[4] === "true" : false);
var throwException = (args.length >= 6 ? args[5] === "true" : false);
try {
console.log(TeXZilla.toMathMLString(tex, display, RTL, throwException));
} catch(e) {
/* FIXME: This should probably call exit with status 1.
https://github.com/fred-wang/TeXZilla/issues/6 */
console.log(e);
}
} else {
/* FIXME: add a stream filter and web server
https://github.com/fred-wang/TeXZilla/issues/7 */
usage(args[0]);
}

/* FIXME: We should use a standard commoneJS syntax for exit.
https://github.com/fred-wang/TeXZilla/issues/6 */
if (slimer) {
slimer.exit()
} else if (phantom) {
phantom.exit()
}
}
12 changes: 8 additions & 4 deletions unit-tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d93e9d7

Please sign in to comment.