|
2 | 2 |
|
3 | 3 | import { toKebabCase } from "kasi"; |
4 | 4 | import { bin, color, exit, parseArgv } from "specialist"; |
5 | | -import { PRETTIER_VERSION } from "./constants.js"; |
| 5 | +import { PRETTIER_VERSION, DEFAULT_PARSERS } from "./constants.js"; |
6 | 6 | import { getPlugin, isBoolean, isNumber, isIntegerInRange, isString } from "./utils.js"; |
7 | 7 | import { normalizeOptions, normalizeFormatOptions, normalizePluginOptions } from "./utils.js"; |
8 | 8 | import type { Bin, PluginsOptions } from "./types.js"; |
@@ -63,9 +63,9 @@ const makeBin = (): Bin => { |
63 | 63 | .option("--jsx-single-quote", 'Use single quotes in JSX\nDefaults to "false"', { |
64 | 64 | section: "Format", |
65 | 65 | }) |
66 | | - .option("--parser <flow|babel|babel-flow|babel-ts|typescript|acorn|espree|meriyah|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|glimmer|html|angular|lwc>", "Which parser to use", { |
| 66 | + .option(`--parser <${DEFAULT_PARSERS.join('|')}>`, "Which parser to use", { |
67 | 67 | section: "Format", |
68 | | - enum: ["flow", "babel", "babel-flow", "babel-ts", "typescript", "acorn", "espree", "meriyah", "css", "less", "scss", "json", "json5", "json-stringify", "graphql", "markdown", "mdx", "vue", "yaml", "glimmer", "html", "angular", "lwc"], |
| 68 | + enum: DEFAULT_PARSERS, |
69 | 69 | }) |
70 | 70 | .option("--print-width <int>", 'The line length where Prettier will try wrap\nDefaults to "80"', { |
71 | 71 | section: "Format", |
@@ -203,6 +203,7 @@ const makePluggableBin = async (): Promise<Bin> => { |
203 | 203 | const formatOptions = normalizeFormatOptions(args); |
204 | 204 | const pluginsDefaultOptions: PluginsOptions = {}; |
205 | 205 | const pluginsNames = formatOptions.plugins || []; |
| 206 | + const pluginsParsers = new Set<string>(); |
206 | 207 | const optionsNames: string[] = []; |
207 | 208 |
|
208 | 209 | for (let i = 0, l = pluginsNames.length; i < l; i++) { |
@@ -252,6 +253,20 @@ const makePluggableBin = async (): Promise<Bin> => { |
252 | 253 | bin = bin.option(`--${toKebabCase(option)} ${args}`, description, { deprecated, section, enum: values }); |
253 | 254 | } |
254 | 255 | } |
| 256 | + |
| 257 | + if (plugin.parsers) { |
| 258 | + for (const parserName of Object.keys(plugin.parsers)) { |
| 259 | + pluginsParsers.add(parserName); |
| 260 | + } |
| 261 | + } |
| 262 | + } |
| 263 | + |
| 264 | + if (pluginsParsers.size) { |
| 265 | + const parsers = [...DEFAULT_PARSERS, ...pluginsParsers]; |
| 266 | + bin.option(`--parser <${parsers}>`, "Which parser to use", { |
| 267 | + section: "Format", |
| 268 | + enum: parsers, |
| 269 | + }); |
255 | 270 | } |
256 | 271 |
|
257 | 272 | bin = bin.action(async (options, files) => { |
|
0 commit comments