Added --quiet option

yargs
gardenapple 4 years ago
parent 227bd1fad9
commit cd196c7b60
No known key found for this signature in database
GPG Key ID: CAF17E9ABE789268

@ -35,6 +35,7 @@ Options:
-p --properties PROP1,[PROP2,...] Output specific properties of the parsed article -p --properties PROP1,[PROP2,...] Output specific properties of the parsed article
-V --version Print version -V --version Print version
-u --url Interpret SOURCE as a URL -u --url Interpret SOURCE as a URL
-q --quiet Don't output extra information to stderr
The --properties option accepts a comma-separated list of values (with no spaces in-between). Suitable values are: The --properties option accepts a comma-separated list of values (with no spaces in-between). Suitable values are:
html-title Outputs the article's title, wrapped in an <h1> tag. html-title Outputs the article's title, wrapped in an <h1> tag.
@ -53,19 +54,21 @@ Default value is "html-title,html-content".`);
const stringArgParams = ['_', "--", "output", "properties"]; const stringArgParams = ['_', "--", "output", "properties"];
const boolArgParams = ["help", "version", "url"]; const boolArgParams = ["quiet", "help", "version", "url"];
const alias = { const alias = {
"output": 'o', "output": 'o',
"properties": 'p', "properties": 'p',
"version": 'V', "version": 'V',
"url": 'u' "url": 'u',
"quiet": 'q'
} }
let args = parseArgs(process.argv.slice(2), { let args = parseArgs(process.argv.slice(2), {
string: stringArgParams, string: stringArgParams,
boolean: boolArgParams, boolean: boolArgParams,
default: { default: {
"properties": "html-title,html-content" "properties": "html-title,html-content",
"quiet": false
}, },
alias: alias, alias: alias,
"--": true "--": true
@ -175,7 +178,8 @@ if (args.properties) {
if (inputIsFromStdin) { if (inputIsFromStdin) {
onLoadDOM(new JSDOM(fs.readFileSync(0, 'utf-8'))); onLoadDOM(new JSDOM(fs.readFileSync(0, 'utf-8')));
} else { } else {
console.error("Retrieving..."); if (!args["quiet"])
console.error("Retrieving...");
let promiseGetHTML; let promiseGetHTML;
if (inputURL) if (inputURL)
promiseGetHTML = JSDOM.fromURL(inputURL); promiseGetHTML = JSDOM.fromURL(inputURL);
@ -187,7 +191,8 @@ if (inputIsFromStdin) {
} }
function onLoadDOM(dom) { function onLoadDOM(dom) {
console.error("Parsing..."); if (!args["quiet"])
console.error("Parsing...");
let reader = new Readability(dom.window.document); let reader = new Readability(dom.window.document);
let article = reader.parse(); let article = reader.parse();
if (!article) { if (!article) {

Loading…
Cancel
Save