refactor: sort usages

master
ikatyang 2017-09-07 13:39:39 +08:00
parent c337f9bb23
commit be22996fd3
2 changed files with 36 additions and 57 deletions

View File

@ -188,10 +188,12 @@ const options = {
} }
}; };
const optionArray = Object.keys(options).reduce( const optionArray = Object.keys(options)
(current, name) => current.concat(Object.assign({ name }, options[name])), .sort()
[] .reduce(
); (current, name) => current.concat(Object.assign({ name }, options[name])),
[]
);
const booleanOptionNames = optionArray const booleanOptionNames = optionArray
.filter(option => option.isFormatOption && option.type === "boolean") .filter(option => option.isFormatOption && option.type === "boolean")
@ -241,33 +243,9 @@ Usage: prettier [opts] [filename ...]
Available options: Available options:
${indent( ${indent(
[ optionArray
"write", .filter(option => !option.isHidden)
"list-different", .map(option => createOptionUsage(option.name, option))
"config",
"config-precedence",
"no-config",
"find-config-path",
"ignore-path",
"stdin",
"stdin-filepath",
"print-width",
"tab-width",
"use-tabs",
"no-semi",
"single-quote",
"no-bracket-spacing",
"jsx-bracket-same-line",
"trailing-comma",
"parser",
"cursor-offset",
"range-start",
"range-end",
"no-color",
"with-node-modules",
"version"
]
.map(name => createOptionUsage(name, options[name]))
.join("\n"), .join("\n"),
2 2
)} )}

View File

@ -4,8 +4,6 @@ exports[`show usage with --help 1`] = `
"Usage: prettier [opts] [filename ...] "Usage: prettier [opts] [filename ...]
Available options: Available options:
--write Edit the file in-place. (Beware!)
--list-different or -l Print filenames of files that are different from Prettier formatting.
--config <path> Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js). --config <path> Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js).
--config-precedence <cli-override|file-override|prefer-file> --config-precedence <cli-override|file-override|prefer-file>
Defines how config file should be evaluated in combination of CLI options Defines how config file should be evaluated in combination of CLI options
@ -14,37 +12,40 @@ Available options:
prefer-file | default config => config file (if config file is found) or prefer-file | default config => config file (if config file is found) or
default config => CLI options (if no config file is found) default config => CLI options (if no config file is found)
Defaults to cli-override Defaults to cli-override
--no-config Do not look for a configuration file.
--find-config-path <path>
Finds and prints the path to a configuration file for a given input file.
--ignore-path <path> Path to a file containing patterns that describe files to ignore.
Defaults to ./.prettierignore.
--stdin Read input from stdin.
--stdin-filepath <path> Path to the file used to read from stdin.
--print-width <int> Specify the length of line that the printer will wrap on. Defaults to 80.
--tab-width <int> Specify the number of spaces per indentation-level. Defaults to 2.
--use-tabs Indent lines with tabs instead of spaces.
--no-semi Do not print semicolons, except at the beginning of lines which may need them.
--single-quote Use single quotes instead of double quotes.
--no-bracket-spacing Do not print spaces between brackets.
--jsx-bracket-same-line Put > on the last line instead of at a new line.
--trailing-comma <none|es5|all>
Print trailing commas wherever possible when multi-line. Defaults to none.
--parser <flow|babylon|typescript|postcss|json|graphql>
Specify which parse to use. Defaults to babylon.
--cursor-offset <int> Print (to stderr) where a cursor at the given position would move to after formatting. --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 This option cannot be used with --range-start and --range-end
--range-start <int> Format code starting at a given character offset. --find-config-path <path>
The range will extend backwards to the start of the first line containing the selected statement. Finds and prints the path to a configuration file for a given input file.
This option cannot be used with --cursor-offset. --help or -h Show help
Defaults to 0. --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.
--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.
--print-width <int> Specify the length of line that the printer will wrap on. Defaults to 80.
--range-end <int> Format code ending at a given character offset (exclusive). --range-end <int> Format code ending at a given character offset (exclusive).
The range will extend forwards to the end of the selected statement. The range will extend forwards to the end of the selected statement.
This option cannot be used with --cursor-offset. This option cannot be used with --cursor-offset.
Defaults to Infinity. Defaults to Infinity.
--no-color Do not colorize error messages. --range-start <int> Format code starting at a given character offset.
--with-node-modules Process files inside 'node_modules' directory. The range will extend backwards to the start of the first line containing the selected statement.
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.
--version or -v Print Prettier version. --version or -v Print Prettier version.
--with-node-modules Process files inside 'node_modules' directory.
--write Edit the file in-place. (Beware!)
" "