Skip to content

Commit 0b846b7

Browse files
committed
fix: no multiline in description
1 parent 4b5dabc commit 0b846b7

6 files changed

Lines changed: 59 additions & 61 deletions

File tree

.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);
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 rsears@salesforce.com 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 rsears@salesforce.com 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 rsears@salesforce.com 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>

yarn.lock

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,7 @@ debug@^2.2.0, debug@^2.3.3:
25662566
dependencies:
25672567
ms "2.0.0"
25682568

2569-
debuglog@*, debuglog@^1.0.1:
2569+
debuglog@^1.0.1:
25702570
version "1.0.1"
25712571
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
25722572
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
@@ -4355,7 +4355,7 @@ import-lazy@^2.1.0:
43554355
resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
43564356
integrity sha1-BWmOPUXIjo1+nZLLBYTnfwlvPkM=
43574357

4358-
imurmurhash@*, imurmurhash@^0.1.4:
4358+
imurmurhash@^0.1.4:
43594359
version "0.1.4"
43604360
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
43614361
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
@@ -5399,11 +5399,6 @@ lockfile@^1.0.4:
53995399
dependencies:
54005400
signal-exit "^3.0.2"
54015401

5402-
lodash._baseindexof@*:
5403-
version "3.1.0"
5404-
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
5405-
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=
5406-
54075402
lodash._baseuniq@~4.6.0:
54085403
version "4.6.0"
54095404
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
@@ -5412,33 +5407,11 @@ lodash._baseuniq@~4.6.0:
54125407
lodash._createset "~4.0.0"
54135408
lodash._root "~3.0.0"
54145409

5415-
lodash._bindcallback@*:
5416-
version "3.0.1"
5417-
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
5418-
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=
5419-
5420-
lodash._cacheindexof@*:
5421-
version "3.0.2"
5422-
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
5423-
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=
5424-
5425-
lodash._createcache@*:
5426-
version "3.1.2"
5427-
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
5428-
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
5429-
dependencies:
5430-
lodash._getnative "^3.0.0"
5431-
54325410
lodash._createset@~4.0.0:
54335411
version "4.0.3"
54345412
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
54355413
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=
54365414

5437-
lodash._getnative@*, lodash._getnative@^3.0.0:
5438-
version "3.9.1"
5439-
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
5440-
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=
5441-
54425415
lodash._reinterpolate@^3.0.0:
54435416
version "3.0.0"
54445417
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
@@ -5514,11 +5487,6 @@ lodash.once@^4.0.0:
55145487
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"
55155488
integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=
55165489

5517-
lodash.restparam@*:
5518-
version "3.6.1"
5519-
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
5520-
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=
5521-
55225490
lodash.template@^4.0.2, lodash.template@^4.4.0:
55235491
version "4.5.0"
55245492
resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab"

0 commit comments

Comments
 (0)