refactor: categorize usages
This commit is contained in:
1 parent
51d5effaf4
commit
c88a45bbf7
3 files changed
+53
-26
No files matched your search
+11
-4
@@ -19,11 +19,13 @@ const detailOptions = normalizer.normalizeDetailOptions({
|
||||
},
|
||||
config: {
|
||||
type: "path",
|
||||
category: "config",
|
||||
description:
|
||||
"Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js)."
|
||||
},
|
||||
"config-precedence": {
|
||||
type: "choice",
|
||||
category: "config",
|
||||
default: "cli-override",
|
||||
choices: ["cli-override", "file-override", "prefer-file"],
|
||||
description: dedent(`
|
||||
@@ -38,7 +40,6 @@ const detailOptions = normalizer.normalizeDetailOptions({
|
||||
"cursor-offset": {
|
||||
type: "int",
|
||||
exception: -1,
|
||||
category: "format",
|
||||
description: dedent(`
|
||||
Print (to stderr) where a cursor at the given position would move to after formatting.
|
||||
This option cannot be used with --range-start and --range-end
|
||||
@@ -54,14 +55,15 @@ const detailOptions = normalizer.normalizeDetailOptions({
|
||||
},
|
||||
"find-config-path": {
|
||||
type: "path",
|
||||
category: "config",
|
||||
description:
|
||||
"Finds and prints the path to a configuration file for a given input file."
|
||||
},
|
||||
"flow-parser": {
|
||||
// Deprecated in 0.0.10
|
||||
type: "boolean",
|
||||
hidden: true,
|
||||
category: "format",
|
||||
hidden: true,
|
||||
deprecated: "Use `--parser flow` instead."
|
||||
},
|
||||
help: {
|
||||
@@ -71,6 +73,7 @@ const detailOptions = normalizer.normalizeDetailOptions({
|
||||
},
|
||||
"ignore-path": {
|
||||
type: "path",
|
||||
category: "config",
|
||||
default: ".prettierignore",
|
||||
description: dedent(`
|
||||
Path to a file containing patterns that describe files to ignore.
|
||||
@@ -90,6 +93,7 @@ const detailOptions = normalizer.normalizeDetailOptions({
|
||||
},
|
||||
"no-bracket-spacing": {
|
||||
type: "boolean",
|
||||
category: "format",
|
||||
description: "Do not print spaces between brackets."
|
||||
},
|
||||
"no-color": {
|
||||
@@ -98,17 +102,19 @@ const detailOptions = normalizer.normalizeDetailOptions({
|
||||
},
|
||||
"no-config": {
|
||||
type: "boolean",
|
||||
category: "config",
|
||||
description: "Do not look for a configuration file."
|
||||
},
|
||||
"no-semi": {
|
||||
type: "boolean",
|
||||
category: "format",
|
||||
description:
|
||||
"Do not print semicolons, except at the beginning of lines which may need them."
|
||||
},
|
||||
parser: {
|
||||
type: "choice",
|
||||
exception: value => typeof value === "string",
|
||||
category: "format",
|
||||
exception: value => typeof value === "string",
|
||||
choices: ["flow", "babylon", "typescript", "postcss", "json", "graphql"],
|
||||
description: "Specify which parse to use. Defaults to babylon.",
|
||||
getter: (value, argv) => (argv["flow-parser"] ? "flow" : value)
|
||||
@@ -121,8 +127,8 @@ const detailOptions = normalizer.normalizeDetailOptions({
|
||||
},
|
||||
"range-end": {
|
||||
type: "int",
|
||||
exception: Infinity,
|
||||
category: "format",
|
||||
exception: Infinity,
|
||||
description: dedent(`
|
||||
Format code ending at a given character offset (exclusive).
|
||||
The range will extend forwards to the end of the selected statement.
|
||||
@@ -188,6 +194,7 @@ const detailOptions = normalizer.normalizeDetailOptions({
|
||||
},
|
||||
"with-node-modules": {
|
||||
type: "boolean",
|
||||
category: "config",
|
||||
description: "Process files inside 'node_modules' directory."
|
||||
},
|
||||
write: {
|
||||
|
||||
+24
-11
@@ -1,19 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
function create(detailOptions) {
|
||||
return `
|
||||
Usage: prettier [opts] [filename ...]
|
||||
const options = detailOptions.filter(option => !option.hidden);
|
||||
|
||||
Available options:
|
||||
${indent(
|
||||
detailOptions
|
||||
.filter(option => !option.hidden)
|
||||
.map(createOptionUsage)
|
||||
.join("\n"),
|
||||
2
|
||||
)}
|
||||
const groupedUsages = options.reduce((current, option) => {
|
||||
const category = capitalize(option.category || "uncategorized");
|
||||
const group = (current[category] = current[category] || []);
|
||||
group.push(createOptionUsage(option));
|
||||
return current;
|
||||
}, {});
|
||||
|
||||
`.slice(1); // remove leading line break
|
||||
let usage = "Usage: prettier [opts] [filename ...]\n\n";
|
||||
|
||||
usage += Object.keys(groupedUsages)
|
||||
.sort()
|
||||
.map(category => {
|
||||
return `${category} options:\n\n${indent(
|
||||
groupedUsages[category].join("\n"),
|
||||
2
|
||||
)}`;
|
||||
})
|
||||
.join("\n\n");
|
||||
|
||||
return usage + "\n\n";
|
||||
}
|
||||
|
||||
function createOptionUsage(option) {
|
||||
@@ -51,6 +60,10 @@ function createOptionUsage(option) {
|
||||
);
|
||||
}
|
||||
|
||||
function capitalize(str) {
|
||||
return str.replace(/^[a-z]/, char => char.toUpperCase());
|
||||
}
|
||||
|
||||
function indent(str, spaces) {
|
||||
return str.replace(/^/gm, " ".repeat(spaces));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
exports[`show usage with --help 1`] = `
|
||||
"Usage: prettier [opts] [filename ...]
|
||||
|
||||
Available options:
|
||||
Config options:
|
||||
|
||||
--config <path> Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js).
|
||||
--config-precedence <cli-override|file-override|prefer-file>
|
||||
Defines how config file should be evaluated in combination of CLI options
|
||||
@@ -12,18 +13,17 @@ Available options:
|
||||
prefer-file | default config => config file (if config file is found) or
|
||||
default config => CLI options (if no config file is found)
|
||||
Defaults to cli-override
|
||||
--cursor-offset <int> Print (to stderr) where a cursor at the given position would move to after formatting.
|
||||
This option cannot be used with --range-start and --range-end
|
||||
--find-config-path <path>
|
||||
Finds and prints the path to a configuration file for a given input file.
|
||||
--help or -h Show help.
|
||||
--ignore-path <path> Path to a file containing patterns that describe files to ignore.
|
||||
Defaults to ./.prettierignore.
|
||||
--jsx-bracket-same-line Put > on the last line instead of at a new line.
|
||||
--list-different or -l Print filenames of files that are different from Prettier formatting.
|
||||
--no-bracket-spacing Do not print spaces between brackets.
|
||||
--no-color Do not colorize error messages.
|
||||
--no-config Do not look for a configuration file.
|
||||
--with-node-modules Process files inside 'node_modules' directory.
|
||||
|
||||
Format options:
|
||||
|
||||
--jsx-bracket-same-line Put > on the last line instead of at a new line.
|
||||
--no-bracket-spacing Do not print spaces between brackets.
|
||||
--no-semi Do not print semicolons, except at the beginning of lines which may need them.
|
||||
--parser <flow|babylon|typescript|postcss|json|graphql>
|
||||
Specify which parse to use. Defaults to babylon.
|
||||
@@ -37,14 +37,21 @@ Available options:
|
||||
This option cannot be used with --cursor-offset.
|
||||
Defaults to 0.
|
||||
--single-quote Use single quotes instead of double quotes.
|
||||
--stdin Read input from stdin.
|
||||
--stdin-filepath <path> Path to the file used to read from stdin.
|
||||
--tab-width <int> Specify the number of spaces per indentation-level. Defaults to 2.
|
||||
--trailing-comma <none|es5|all>
|
||||
Print trailing commas wherever possible when multi-line. Defaults to none.
|
||||
--use-tabs Indent lines with tabs instead of spaces.
|
||||
|
||||
Uncategorized options:
|
||||
|
||||
--cursor-offset <int> Print (to stderr) where a cursor at the given position would move to after formatting.
|
||||
This option cannot be used with --range-start and --range-end
|
||||
--help or -h Show help.
|
||||
--list-different or -l Print filenames of files that are different from Prettier formatting.
|
||||
--no-color Do not colorize error messages.
|
||||
--stdin Read input from stdin.
|
||||
--stdin-filepath <path> Path to the file used to read from stdin.
|
||||
--version or -v Print Prettier version.
|
||||
--with-node-modules Process files inside 'node_modules' directory.
|
||||
--write Edit the file in-place. (Beware!)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user