Skip to content

Commit e1e0540

Browse files
committed
Add CLI support
1 parent e7bc5eb commit e1e0540

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "bash-parser",
33
"version": "0.5.0",
44
"main": "src/index.js",
5+
"bin": "src/cli.js",
56
"description": "Standard compliant bash parser",
67
"repository": "vorpaljs/bash-parser",
78
"license": "MIT",

src/cli.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const parse = require('../');
6+
const pkg = require('../package');
7+
8+
const args = process.argv.slice(2);
9+
10+
if (!args.length || args.includes('--help') || args.includes('-h')) {
11+
console.log(`${pkg.name}${pkg.description}\n\nUsage:\n\n\t${pkg.name} <source>`);
12+
process.exit();
13+
}
14+
15+
if (args.includes('--version') || args.includes('-v')) {
16+
console.log(pkg.version);
17+
process.exit();
18+
}
19+
20+
const [sourceCode] = args;
21+
const ast = parse(sourceCode);
22+
console.log(JSON.stringify(ast, null, '\t'));

0 commit comments

Comments
 (0)