|
|
@ -20,12 +20,12 @@ function error(exitCode) {
|
|
|
|
function printUsage() {
|
|
|
|
function printUsage() {
|
|
|
|
console.error(`
|
|
|
|
console.error(`
|
|
|
|
Usage:
|
|
|
|
Usage:
|
|
|
|
readable SOURCE [options]
|
|
|
|
readable [SOURCE] [options]
|
|
|
|
readable [options] -- SOURCE
|
|
|
|
readable [options] -- [SOURCE]
|
|
|
|
(where SOURCE is a file, an http(s) URL, or '-' for standard input)
|
|
|
|
(where SOURCE is a file, an http(s) URL, or '-' for standard input)
|
|
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
Options:
|
|
|
|
-h --help Print help
|
|
|
|
--help Print help
|
|
|
|
-o --output OUTPUT_FILE Output to OUTPUT_FILE`);
|
|
|
|
-o --output OUTPUT_FILE Output to OUTPUT_FILE`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -35,7 +35,6 @@ const stringArgParams = ['_', '--', "output"];
|
|
|
|
const boolArgParams = ["help"];
|
|
|
|
const boolArgParams = ["help"];
|
|
|
|
const alias = {
|
|
|
|
const alias = {
|
|
|
|
"output": 'o',
|
|
|
|
"output": 'o',
|
|
|
|
"help": 'h'
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let args = parseArgs(process.argv.slice(2), {
|
|
|
|
let args = parseArgs(process.argv.slice(2), {
|
|
|
@ -71,6 +70,7 @@ if (args.help) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let inputArg;
|
|
|
|
const inputCount = args['_'].length + args['--'].length;
|
|
|
|
const inputCount = args['_'].length + args['--'].length;
|
|
|
|
if (inputCount > 1) {
|
|
|
|
if (inputCount > 1) {
|
|
|
|
console.error("Too many input arguments");
|
|
|
|
console.error("Too many input arguments");
|
|
|
@ -78,10 +78,16 @@ if (inputCount > 1) {
|
|
|
|
error(ExitCodes.badUsageCLI);
|
|
|
|
error(ExitCodes.badUsageCLI);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
} else if (inputCount == 0) {
|
|
|
|
} else if (inputCount == 0) {
|
|
|
|
console.error("No input argument given. Use 'readable -' to read standard input");
|
|
|
|
if (process.stdin.isTTY) {
|
|
|
|
printUsage();
|
|
|
|
console.error("No input provided");
|
|
|
|
error(ExitCodes.badUsageCLI);
|
|
|
|
printUsage();
|
|
|
|
return;
|
|
|
|
error(ExitCodes.badUsageCLI);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
inputArg = '-'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
inputArg = (args['_'].length > 0) ? args['_'][0] : args['--'][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Get input parameter, remove inputArg from args
|
|
|
|
//Get input parameter, remove inputArg from args
|
|
|
@ -89,11 +95,9 @@ let inputFile;
|
|
|
|
let inputURL;
|
|
|
|
let inputURL;
|
|
|
|
let inputIsFromStdin = false;
|
|
|
|
let inputIsFromStdin = false;
|
|
|
|
|
|
|
|
|
|
|
|
const inputArg = (args['_'].length > 0) ? args['_'][0] : args['--'][0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inputArg.startsWith("https://") || inputArg.startsWith("http://"))
|
|
|
|
if (inputArg.startsWith("https://") || inputArg.startsWith("http://"))
|
|
|
|
inputURL = inputArg;
|
|
|
|
inputURL = inputArg;
|
|
|
|
else if (args['_'] == '-')
|
|
|
|
else if (inputArg == '-')
|
|
|
|
inputIsFromStdin = true;
|
|
|
|
inputIsFromStdin = true;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
inputFile = inputArg;
|
|
|
|
inputFile = inputArg;
|
|
|
|