-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·50 lines (42 loc) · 1.17 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
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
'use strict';
process.title = 'expand-object';
var argv = require('minimist')(process.argv.slice(2));
var stdin = require('get-stdin');
var expand = require('./index');
var pkg = require('./package.json');
function help() {
console.log();
console.log(' ' + pkg.description);
console.log();
console.log(' Usage: cli [options] <string>');
console.log();
console.log(' -h, --help output usage information');
console.log(' -V, --version output the version number');
console.log(' -r, --raw output as raw javascript object - don\'t stringify');
console.log();
console.log(' Examples:');
console.log('');
console.log(' $ expand-object "a:b"');
console.log(' $ expand-object --raw "a:b"');
console.log(' $ echo "a:b" | expand-object');
console.log('');
}
if (argv._.length === 0 && Object.keys(argv).length === 1 || argv.help) {
help();
}
function run(contents) {
var output = expand(contents);
if (!argv.raw) {
output = JSON.stringify(output);
}
console.log(output);
process.exit(0);
}
if (!process.stdin.isTTY) {
stdin(function(contents) {
run(contents);
});
} else {
run(argv._[0] || '');
}