refactor: wrap usage in function

master
ikatyang 2017-09-08 15:31:59 +08:00
parent a1c3350bd1
commit 2de3b13175
2 changed files with 14 additions and 12 deletions

View File

@ -1,20 +1,20 @@
"use strict"; "use strict";
const constant = require("./cli-constant"); function create(detailOptions) {
return `
const usage = `
Usage: prettier [opts] [filename ...] Usage: prettier [opts] [filename ...]
Available options: Available options:
${indent( ${indent(
constant.options detailOptions
.filter(option => !option.isHidden) .filter(option => !option.isHidden)
.map(createOptionUsage) .map(createOptionUsage)
.join("\n"), .join("\n"),
2 2
)} )}
`.slice(1); // remove leading line break `.slice(1); // remove leading line break
}
function createOptionUsage(option) { function createOptionUsage(option) {
const threshold = 25; const threshold = 25;
@ -55,4 +55,6 @@ function indent(str, spaces) {
return str.replace(/^/gm, " ".repeat(spaces)); return str.replace(/^/gm, " ".repeat(spaces));
} }
module.exports = usage; module.exports = {
create
};

View File

@ -26,7 +26,7 @@ function run(args) {
} }
if (argv["help"]) { if (argv["help"]) {
console.log(usage); console.log(usage.create(constant.options));
process.exit(0); process.exit(0);
} }
@ -40,7 +40,7 @@ function run(args) {
} else if (hasFilePatterns) { } else if (hasFilePatterns) {
util.formatFiles(argv); util.formatFiles(argv);
} else { } else {
console.log(usage); console.log(usage.create(constant.options));
process.exit(1); process.exit(1);
} }
} }