Skip to content

Commit ecd2abf

Browse files
authored
Merge pull request #3 from forcedotcom/td/update
Fix multiline description
2 parents ec455bd + fe00112 commit ecd2abf

File tree

7 files changed

+149
-112
lines changed

7 files changed

+149
-112
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/templates

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": false
3+
}

src/ditamap/command.ts

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,42 @@
77

88
import { asString, Dictionary, ensureJsonMap, ensureObject, ensureString, JsonMap } from '@salesforce/ts-types';
99
import { join } from 'path';
10-
import { punctuate } from '../utils';
10+
import { helpFromDescription, punctuate } from '../utils';
1111
import { Ditamap } from './ditamap';
1212

13+
export type CommandHelpInfo = {
14+
hidden: boolean;
15+
description: string;
16+
longDescription: string;
17+
required: boolean;
18+
kind: string;
19+
type: string;
20+
};
21+
1322
export class Command extends Ditamap {
1423
constructor(topic: string, subtopic: string, command: Dictionary, commandMeta: JsonMap = {}) {
1524
const commandWithUnderscores = ensureString(command.id).replace(/:/g, '_');
1625
const filename = `cli_reference_${commandWithUnderscores}.xml`;
1726

18-
const flags = ensureObject(command.flags);
19-
2027
super(filename, {});
2128

22-
const parameters = Object.entries(flags)
23-
.filter(([, flag]) => !flag.hidden)
24-
.map(([flagName, flag]) => {
25-
if (!flag.longDescription) {
26-
flag.longDescription = punctuate(flag.description);
27-
}
28-
return Object.assign(flag, {
29-
name: flagName,
30-
longDescriptionPs: this.formatParagraphs(flag.longDescription),
31-
optional: !flag.required,
32-
kind: flag.kind || flag.type,
33-
hasValue: flag.type !== 'boolean'
34-
});
35-
});
29+
const flags = ensureObject(command.flags);
30+
const parameters = this.getParametersForTemplate(flags as Dictionary<CommandHelpInfo>);
3631

32+
// The template only expects a oneline description. Punctuate the first line of either the lingDescription or description.
33+
const description = punctuate(asString(command.longDescription) || asString(command.description));
34+
// Help are all the lines after the first line in the description. Before oclif, there was a 'help' property so continue to
35+
// support that.
36+
const help = this.formatParagraphs(asString(command.help) || helpFromDescription(asString(command.description)));
3737
let trailblazerCommunityUrl;
3838
let trailblazerCommunityName;
39+
3940
if (commandMeta.trailblazerCommunityLink) {
4041
const community = ensureJsonMap(commandMeta.trailblazerCommunityLink);
4142
trailblazerCommunityUrl = community.url;
4243
trailblazerCommunityName = community.name;
4344
}
4445

45-
if (!command.longDescription) {
46-
command.longDescription = punctuate(asString(command.description));
47-
}
48-
4946
let fullName: string;
5047
if (subtopic) {
5148
fullName = commandWithUnderscores.replace(`${topic}_${subtopic}_`, '');
@@ -57,8 +54,8 @@ export class Command extends Ditamap {
5754
binary: 'sfdx',
5855
// The old style didn't have the topic or subtopic in the reference ID.
5956
full_name_with_underscores: fullName,
60-
helpPs: this.formatParagraphs(asString(command.help)),
61-
longDescriptionPs: this.formatParagraphs(asString(command.longDescription)),
57+
help,
58+
description,
6259
parameters,
6360
isClosedPilotCommand: state === 'closedPilot',
6461
isOpenPilotCommand: state === 'openPilot',
@@ -75,6 +72,24 @@ export class Command extends Ditamap {
7572
}
7673
}
7774

75+
public getParametersForTemplate(flags: Dictionary<CommandHelpInfo>) {
76+
Object.entries(flags)
77+
.filter(([, flag]) => !flag.hidden)
78+
.map(([flagName, flag]) => {
79+
const description = this.formatParagraphs(flag.longDescription || punctuate(flag.description));
80+
if (!flag.longDescription) {
81+
flag.longDescription = punctuate(flag.description);
82+
}
83+
return Object.assign(flag, {
84+
name: flagName,
85+
description,
86+
optional: !flag.required,
87+
kind: flag.kind || flag.type,
88+
hasValue: flag.type !== 'boolean'
89+
});
90+
});
91+
}
92+
7893
public getTemplateFileName(): string {
7994
return 'command.hbs';
8095
}

src/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,14 @@ export function punctuate(description: string): string {
4343
if (mainDescription.charAt(mainDescription.length - 1) !== '.') {
4444
mainDescription += '.';
4545
}
46-
return [mainDescription, ...lines.slice(1)].join(EOL);
46+
47+
return mainDescription;
48+
}
49+
50+
export function helpFromDescription(description: string): string {
51+
return description
52+
.split(EOL)
53+
.slice(1)
54+
.join(EOL)
55+
.trim();
4756
}

templates/command.hbs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ IF YOU WANT TO CHANGE THIS CONTENT, CONTACT [email protected] FOR DETAILS.
1010
-->
1111
{{!--Not all commands have a minor noun; some are just commandmajornoun:commandverb. This is a sample topic for a commmand with no minor noun.--}}
1212
<title><ph id="topic-title"><codeph otherprops="nolang">{{id}}</codeph>{{#if isClosedPilotCommand}} (Pilot){{/if}}{{#if isOpenPilotCommand}} (Pilot){{/if}}{{#if isBetaCommand}} (Beta){{/if}}{{#if deprecated}} (Deprecated){{/if}}</ph></title>
13-
<shortdesc><ph id="shortdesc">{{#if deprecated}}The command <codeph otherprops="nolang">{{id}}</codeph> has been deprecated and will be removed in v{{nextVersion deprecated.version}}.0 or later. Use <codeph otherprops="nolang">{{deprecated.to}}</codeph> instead. {{/if}}{{#if longDescription}}{{longDescription}}{{else}}{{description}}{{/if}}</ph></shortdesc>
13+
<shortdesc><ph id="shortdesc">{{#if deprecated}}The command <codeph otherprops="nolang">{{id}}</codeph> has been deprecated and will be removed in v{{nextVersion deprecated.version}}.0 or later. Use <codeph otherprops="nolang">{{deprecated.to}}</codeph> instead. {{/if}}{{description}}</ph></shortdesc>
1414
<prolog>
1515
<metadata>
1616
{{!--In the future we’ll add keywords here.--}}
@@ -81,7 +81,7 @@ IF YOU WANT TO CHANGE THIS CONTENT, CONTACT [email protected] FOR DETAILS.
8181
<dt>{{#if char}}<codeph otherprops="nolang">-{{char}}</codeph> | {{/if}}<codeph otherprops="nolang">--{{name}}</codeph>{{#if hasValue}} <parmname>{{toUpperCase name}}</parmname>{{/if}}</dt>
8282
{{#if deprecated}}<dd>The parameter <codeph otherprops="nolang">--{{name}}</codeph> has been deprecated and will be removed in v{{nextVersion deprecated.version}}.0 or later. Use <codeph otherprops="nolang">{{deprecated.to}}</codeph> instead.</dd>
8383
{{/if}}<dd>{{#if optional}}Optional{{else}}Required{{/if}}</dd>
84-
<dd>{{#if longDescriptionPs}}{{#each longDescriptionPs}}<p>{{[]}}</p>{{/each}}{{else}}<p>{{description}}</p>{{/if}}</dd>{{#if kind}}
84+
<dd><p>{{description}}</p></dd>{{#if kind}}
8585
<dd>Type: {{kind}}</dd>{{/if}}{{#if options}}
8686
<dd>Permissible values are: {{join options}}</dd>{{/if}}{{#if default}}
8787
<dd>Default value: {{default}}</dd>{{/if}}
@@ -90,11 +90,13 @@ IF YOU WANT TO CHANGE THIS CONTENT, CONTACT [email protected] FOR DETAILS.
9090
</dl>
9191
</section>
9292
{{/if}}
93+
{{#if help}}
9394
<section>
9495
<title><ph>Help for <codeph otherprops="nolang">{{id}}</codeph></ph></title>
95-
{{#each helpPs}}
96+
{{#each help}}
9697
{{#isCodeBlock this}}<codeblock otherprops="nolang">{{this}}</codeblock>{{else}}<p>{{this}}</p>{{/isCodeBlock}}
9798
{{/each}}
9899
</section>
100+
{{/if}}
99101
</refbody>
100102
</reference>

test/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('punctuate', () => {
4646

4747
it('multi line descriptions to longDescriptions', () => {
4848
expect(punctuate(`lowercase oclif description${EOL}${EOL}some other stuff`)).to.equal(
49-
`Lowercase oclif description.${EOL}${EOL}some other stuff`
49+
'Lowercase oclif description.'
5050
);
5151
});
5252

0 commit comments

Comments
 (0)