-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
41 lines (37 loc) · 1 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var fs = require('fs');
function usage() {
process.stdout.write("Usage: grassmudmonkey [-w | --whitespace] <file>\n");
process.stdout.write("\n");
process.stdout.write(" -w, --whitespace\n");
process.stdout.write(" Use Whitespace syntax instead of GrassMudMonkey syntax\n");
process.stdout.write(" <file>\n");
process.stdout.write(" Filename of the program\n");
process.exit(2);
}
let type = 'GrassMudHorse';
let filename = null;
for (let i = 2; i < process.argv.length; i++) {
const arg = process.argv[i];
if (arg === "--whitespace" || arg == '-w') {
type = 'Whitespace';
} else {
if (filename !== null) {
usage();
}
filename = arg;
}
}
if (filename === null) {
usage();
}
let program;
try {
program = fs.readFileSync(filename, "utf-8");
} catch (e) {
process.stdout.write(e.toString());
process.stdout.write("\n");
process.exit(1);
}
GrassMudMonkey.type = type;
GrassMudMonkey.print = s => process.stdout.write(s);
GrassMudMonkey.eval(program)