Skip to content

Commit 65863de

Browse files
committed
fix(packages/extensions): use breaking withUsageExtensions call signature
1 parent 5148bc0 commit 65863de

File tree

2 files changed

+105
-77
lines changed

2 files changed

+105
-77
lines changed

packages/extensions/src/index.ts

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,53 +1374,58 @@ export function withBuilderExtensions<
13741374
* Generate command usage text consistently yet flexibly.
13751375
*
13761376
* Defaults to: `Usage: $000\n\n${altDescription}` where `altDescription` is
1377-
* `$1.`
1377+
* `"$1."`.
13781378
*/
1379-
export function withUsageExtensions(
1379+
export function withUsageExtensions({
13801380
altDescription = '$1.',
1381-
{
1382-
trim = true,
1383-
appendPeriod = true,
1384-
prependNewlines = true,
1385-
includeOptions = prependNewlines,
1386-
includeSubCommand = false
1387-
}: {
1388-
/**
1389-
* Whether `altDescription` will be `trim()`'d or not.
1390-
*
1391-
* @default true
1392-
*/
1393-
trim?: boolean;
1394-
/**
1395-
* Whether a period will be appended to the resultant string or not. A
1396-
* period is only appended if one is not already appended.
1397-
*
1398-
* @default true
1399-
*/
1400-
appendPeriod?: boolean;
1401-
/**
1402-
* Whether newlines will be prepended to `altDescription` or not.
1403-
*
1404-
* @default true
1405-
*/
1406-
prependNewlines?: boolean;
1407-
/**
1408-
* Whether the string `' [...options]'` will be appended to the first line
1409-
* of usage text (after `includeSubCommand`).
1410-
*
1411-
* @default options.prependNewlines
1412-
*/
1413-
includeOptions?: boolean;
1414-
/**
1415-
* Whether some variation of the string `' [subcommand]'` will be appended
1416-
* to the first line of usage text (before `includeOptions`). Set to `true`
1417-
* or `required` when generating usage for a command with subcommands.
1418-
*
1419-
* @default false
1420-
*/
1421-
includeSubCommand?: boolean | 'required';
1422-
} = {}
1423-
) {
1381+
trim = true,
1382+
appendPeriod = true,
1383+
prependNewlines = true,
1384+
includeOptions = prependNewlines,
1385+
includeSubCommand = false
1386+
}: {
1387+
/**
1388+
* The result of calling this function defaults to: `Usage:
1389+
* $000\n\n${altDescription}`.
1390+
*
1391+
* @default "$1."
1392+
*/
1393+
altDescription?: string;
1394+
/**
1395+
* Whether `altDescription` will be `trim()`'d or not.
1396+
*
1397+
* @default true
1398+
*/
1399+
trim?: boolean;
1400+
/**
1401+
* Whether a period will be appended to the resultant string or not. A
1402+
* period is only appended if one is not already appended.
1403+
*
1404+
* @default true
1405+
*/
1406+
appendPeriod?: boolean;
1407+
/**
1408+
* Whether newlines will be prepended to `altDescription` or not.
1409+
*
1410+
* @default true
1411+
*/
1412+
prependNewlines?: boolean;
1413+
/**
1414+
* Whether the string `' [...options]'` will be appended to the first line
1415+
* of usage text (after `includeSubCommand`).
1416+
*
1417+
* @default options.prependNewlines
1418+
*/
1419+
includeOptions?: boolean;
1420+
/**
1421+
* Whether some variation of the string `' [subcommand]'` will be appended
1422+
* to the first line of usage text (before `includeOptions`). Set to `true`
1423+
* or `required` when generating usage for a command with subcommands.
1424+
*
1425+
* @default false
1426+
*/
1427+
includeSubCommand?: boolean | 'required';
1428+
} = {}) {
14241429
return `Usage: $000${
14251430
includeSubCommand === 'required'
14261431
? ' <subcommand>'

packages/extensions/test/unit.test.ts

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5789,7 +5789,7 @@ describe('::withUsageExtensions', () => {
57895789

57905790
it('appends passed parameter to consistent usage string template', async () => {
57915791
expect.hasAssertions();
5792-
expect(withUsageExtensions('new description')).toBe(
5792+
expect(withUsageExtensions({ altDescription: 'new description' })).toBe(
57935793
'Usage: $000 [...options]\n\nnew description.'
57945794
);
57955795
});
@@ -5801,11 +5801,11 @@ describe('::withUsageExtensions', () => {
58015801
new description
58025802
`;
58035803

5804-
expect(withUsageExtensions(expected, { trim: true })).toBe(
5804+
expect(withUsageExtensions({ altDescription: expected, trim: true })).toBe(
58055805
`Usage: $000 [...options]\n\n${expected.trim()}.`
58065806
);
58075807

5808-
expect(withUsageExtensions(expected, { trim: false })).toBe(
5808+
expect(withUsageExtensions({ altDescription: expected, trim: false })).toBe(
58095809
`Usage: $000 [...options]\n\n${expected}.`
58105810
);
58115811
});
@@ -5817,11 +5817,11 @@ new description
58175817
new description
58185818
`;
58195819

5820-
expect(withUsageExtensions(expected, { appendPeriod: true })).toBe(
5820+
expect(withUsageExtensions({ altDescription: expected, appendPeriod: true })).toBe(
58215821
`Usage: $000 [...options]\n\n${expected.trim()}.`
58225822
);
58235823

5824-
expect(withUsageExtensions(expected, { appendPeriod: false })).toBe(
5824+
expect(withUsageExtensions({ altDescription: expected, appendPeriod: false })).toBe(
58255825
`Usage: $000 [...options]\n\n${expected.trim()}`
58265826
);
58275827
});
@@ -5833,17 +5833,21 @@ new description
58335833
new description
58345834
`;
58355835

5836-
expect(withUsageExtensions(expected, { prependNewlines: true })).toBe(
5837-
`Usage: $000 [...options]\n\n${expected.trim()}.`
5838-
);
5836+
expect(
5837+
withUsageExtensions({ altDescription: expected, prependNewlines: true })
5838+
).toBe(`Usage: $000 [...options]\n\n${expected.trim()}.`);
58395839

5840-
expect(withUsageExtensions(expected, { prependNewlines: false })).toBe(
5841-
`Usage: $000${expected.trim()}.`
5842-
);
5840+
expect(
5841+
withUsageExtensions({ altDescription: expected, prependNewlines: false })
5842+
).toBe(`Usage: $000${expected.trim()}.`);
58435843

5844-
expect(withUsageExtensions(expected, { prependNewlines: false, trim: false })).toBe(
5845-
`Usage: $000${expected}.`
5846-
);
5844+
expect(
5845+
withUsageExtensions({
5846+
altDescription: expected,
5847+
prependNewlines: false,
5848+
trim: false
5849+
})
5850+
).toBe(`Usage: $000${expected}.`);
58475851
});
58485852

58495853
it('respects "includeOptions" option', async () => {
@@ -5854,15 +5858,23 @@ new description
58545858
`;
58555859

58565860
expect(
5857-
withUsageExtensions(expected, { includeOptions: true, prependNewlines: false })
5861+
withUsageExtensions({
5862+
altDescription: expected,
5863+
includeOptions: true,
5864+
prependNewlines: false
5865+
})
58585866
).toBe(`Usage: $000 [...options]${expected.trim()}.`);
58595867

5860-
expect(withUsageExtensions(expected, { includeOptions: false })).toBe(
5861-
`Usage: $000\n\n${expected.trim()}.`
5862-
);
5868+
expect(
5869+
withUsageExtensions({ altDescription: expected, includeOptions: false })
5870+
).toBe(`Usage: $000\n\n${expected.trim()}.`);
58635871

58645872
expect(
5865-
withUsageExtensions(expected, { includeOptions: false, prependNewlines: true })
5873+
withUsageExtensions({
5874+
altDescription: expected,
5875+
includeOptions: false,
5876+
prependNewlines: true
5877+
})
58665878
).toBe(`Usage: $000\n\n${expected.trim()}.`);
58675879
});
58685880

@@ -5873,17 +5885,17 @@ new description
58735885
new description
58745886
`;
58755887

5876-
expect(withUsageExtensions(expected, { includeSubCommand: true })).toBe(
5877-
`Usage: $000 [subcommand] [...options]\n${expected.trimEnd()}.`
5878-
);
5888+
expect(
5889+
withUsageExtensions({ altDescription: expected, includeSubCommand: true })
5890+
).toBe(`Usage: $000 [subcommand] [...options]\n${expected.trimEnd()}.`);
58795891

5880-
expect(withUsageExtensions(expected, { includeSubCommand: false })).toBe(
5881-
`Usage: $000 [...options]\n\n${expected.trim()}.`
5882-
);
5892+
expect(
5893+
withUsageExtensions({ altDescription: expected, includeSubCommand: false })
5894+
).toBe(`Usage: $000 [...options]\n\n${expected.trim()}.`);
58835895

5884-
expect(withUsageExtensions(expected, { includeSubCommand: 'required' })).toBe(
5885-
`Usage: $000 <subcommand> [...options]\n${expected.trimEnd()}.`
5886-
);
5896+
expect(
5897+
withUsageExtensions({ altDescription: expected, includeSubCommand: 'required' })
5898+
).toBe(`Usage: $000 <subcommand> [...options]\n${expected.trimEnd()}.`);
58875899
});
58885900

58895901
it('respects "includeOptions" + "includeSubCommand" options together', async () => {
@@ -5894,15 +5906,24 @@ new description
58945906
`;
58955907

58965908
expect(
5897-
withUsageExtensions(expected, { includeOptions: true, includeSubCommand: true })
5909+
withUsageExtensions({
5910+
altDescription: expected,
5911+
includeOptions: true,
5912+
includeSubCommand: true
5913+
})
58985914
).toBe(`Usage: $000 [subcommand] [...options]\n${expected.trimEnd()}.`);
58995915

59005916
expect(
5901-
withUsageExtensions(expected, { includeOptions: true, includeSubCommand: false })
5917+
withUsageExtensions({
5918+
altDescription: expected,
5919+
includeOptions: true,
5920+
includeSubCommand: false
5921+
})
59025922
).toBe(`Usage: $000 [...options]\n${expected.trimEnd()}.`);
59035923

59045924
expect(
5905-
withUsageExtensions(expected, {
5925+
withUsageExtensions({
5926+
altDescription: expected,
59065927
includeOptions: true,
59075928
includeSubCommand: 'required'
59085929
})
@@ -5916,7 +5937,9 @@ new description
59165937
const str =
59175938
"$1.\n\nAdditional description text that only appears in this command's help text.";
59185939

5919-
expect(withUsageExtensions(str)).toBe(`Usage: $000 [...options]\n\n${str}`);
5940+
expect(withUsageExtensions({ altDescription: str })).toBe(
5941+
`Usage: $000 [...options]\n\n${str}`
5942+
);
59205943
});
59215944
});
59225945
});

0 commit comments

Comments
 (0)