feat(cli): allow overriding (#5390)
parent
de11f69889
commit
b0b5460e8f
|
@ -158,6 +158,18 @@ function optionInfoToSchema(optionInfo, { isCLI, optionInfos }) {
|
|||
handlers.deprecated = true;
|
||||
}
|
||||
|
||||
// allow CLI overriding, e.g., prettier package.json --tab-width 1 --tab-width 2
|
||||
if (isCLI && !optionInfo.array) {
|
||||
const originalPreprocess = parameters.preprocess || (x => x);
|
||||
parameters.preprocess = (value, schema, utils) =>
|
||||
schema.preprocess(
|
||||
originalPreprocess(
|
||||
Array.isArray(value) ? value[value.length - 1] : value
|
||||
),
|
||||
utils
|
||||
);
|
||||
}
|
||||
|
||||
return optionInfo.array
|
||||
? vnopts.ArraySchema.create(
|
||||
Object.assign(
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`allow overriding flags (stderr) 1`] = `""`;
|
||||
|
||||
exports[`allow overriding flags (write) 1`] = `Array []`;
|
||||
|
||||
exports[`boolean flags do not swallow the next argument (stderr) 1`] = `""`;
|
||||
|
||||
exports[`boolean flags do not swallow the next argument (stdout) 1`] = `
|
||||
|
|
|
@ -37,3 +37,14 @@ describe("deprecated option values are warned", () => {
|
|||
status: 0
|
||||
});
|
||||
});
|
||||
|
||||
describe("allow overriding flags", () => {
|
||||
runPrettier(
|
||||
"cli/arg-parsing",
|
||||
["--tab-width=1", "--tab-width=3", "--parser=babylon"],
|
||||
{ input: "function a() { b }" }
|
||||
).test({
|
||||
stdout: "function a() {\n b;\n}\n",
|
||||
status: 0
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue