-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·54 lines (41 loc) · 998 Bytes
/
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
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const meow = require('meow');
const brunfaick = require('.');
const help = `
Usage
$ brunfaick [program]
Options
-f, --file
Path to a Brainfuck file.
-i, --input
Input provided to [program] during execution.
Examples
$ brunfaick '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.'
Hello World!
$ brunfaick --file=hello-world.b
Hello World!
$ brunfaick --file=wc.b --input='foo bar baz'
0 3 11
`;
const opts = {
alias: {
i: 'input',
f: 'file',
},
};
const cli = meow(help, opts);
const program = cli.input[0];
const input = cli.flags.input;
const file = cli.flags.file;
if (file) {
fs.readFile(file, 'utf8', (err, program) => {
const output = err ?
err.message :
brunfaick(program, input);
console.log(output);
});
} else {
console.log(brunfaick(program, input));
}