mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
856 B
48 lines
856 B
11 years ago
|
#!/usr/bin/env node
|
||
|
'use strict';
|
||
|
var fs = require('fs');
|
||
|
var pkg = require('./package.json');
|
||
10 years ago
|
var stripAnsi = require('./');
|
||
|
var argv = process.argv.slice(2);
|
||
|
var input = argv[0];
|
||
11 years ago
|
|
||
|
function help() {
|
||
|
console.log([
|
||
|
'',
|
||
10 years ago
|
' ' + pkg.description,
|
||
11 years ago
|
'',
|
||
10 years ago
|
' Usage',
|
||
|
' strip-ansi <input-file> > <output-file>',
|
||
|
' cat <input-file> | strip-ansi > <output-file>',
|
||
|
'',
|
||
|
' Example',
|
||
|
' strip-ansi unicorn.txt > unicorn-stripped.txt'
|
||
11 years ago
|
].join('\n'));
|
||
|
}
|
||
|
|
||
10 years ago
|
function init(data) {
|
||
|
process.stdout.write(stripAnsi(data));
|
||
|
}
|
||
|
|
||
|
if (argv.indexOf('--help') !== -1) {
|
||
11 years ago
|
help();
|
||
|
return;
|
||
|
}
|
||
|
|
||
10 years ago
|
if (argv.indexOf('--version') !== -1) {
|
||
11 years ago
|
console.log(pkg.version);
|
||
|
return;
|
||
|
}
|
||
|
|
||
10 years ago
|
if (!input && process.stdin.isTTY) {
|
||
|
help();
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
if (input) {
|
||
10 years ago
|
init(fs.readFileSync(input, 'utf8'));
|
||
|
} else {
|
||
|
process.stdin.setEncoding('utf8');
|
||
|
process.stdin.on('data', init);
|
||
|
}
|