summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/strip-ansi/cli.js
blob: b83f63b907e2e0409c96bebf842339b528b771c4 (plain)
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
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var pkg = require('./package.json');
var stripAnsi = require('./');
var argv = process.argv.slice(2);
var input = argv[0];

function help() {
	console.log([
		'',
		'  ' + pkg.description,
		'',
		'  Usage',
		'    strip-ansi <input-file> > <output-file>',
		'    cat <input-file> | strip-ansi > <output-file>',
		'',
		'  Example',
		'    strip-ansi unicorn.txt > unicorn-stripped.txt'
	].join('\n'));
}

function init(data) {
	process.stdout.write(stripAnsi(data));
}

if (argv.indexOf('--help') !== -1) {
	help();
	return;
}

if (argv.indexOf('--version') !== -1) {
	console.log(pkg.version);
	return;
}

if (!input && process.stdin.isTTY) {
	help();
	return;
}

if (input) {
	init(fs.readFileSync(input, 'utf8'));
} else {
	process.stdin.setEncoding('utf8');
	process.stdin.on('data', init);
}