Initial commit
[yaffs-website] / node_modules / strip-indent / cli.js
1 #!/usr/bin/env node
2 'use strict';
3 var fs = require('fs');
4 var stdin = require('get-stdin');
5 var pkg = require('./package.json');
6 var stripIndent = require('./');
7 var argv = process.argv.slice(2);
8 var input = argv[0];
9
10 function help() {
11         console.log([
12                 '',
13                 '  ' + pkg.description,
14                 '',
15                 '  Usage',
16                 '    strip-indent <file>',
17                 '    echo <string> | strip-indent',
18                 '',
19                 '  Example',
20                 '    echo \'\\tunicorn\\n\\t\\tcake\' | strip-indent',
21                 '    unicorn',
22                 '    \tcake'
23         ].join('\n'));
24 }
25
26 function init(data) {
27         console.log(stripIndent(data));
28 }
29
30 if (argv.indexOf('--help') !== -1) {
31         help();
32         return;
33 }
34
35 if (argv.indexOf('--version') !== -1) {
36         console.log(pkg.version);
37         return;
38 }
39
40 if (process.stdin.isTTY) {
41         if (!input) {
42                 help();
43                 return;
44         }
45
46         init(fs.readFileSync(input, 'utf8'));
47 } else {
48         stdin(init);
49 }