Skip to content

Commit b799259

Browse files
committed
fix: do not warn on single command topics
1 parent 11ca2ad commit b799259

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/docs.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class Docs {
7676
if (!isArray(subtopicOrCommand)) {
7777
// If it is not subtopic (array) it is a command in the top-level topic
7878
const command = subtopicOrCommand;
79-
const commandMeta = this.resolveCommandMeta(ensureString(command.id));
79+
const commandMeta = this.resolveCommandMeta(ensureString(command.id), command, 1);
8080
await this.populateCommand(topic, null, command, commandMeta);
8181
commandNames.push(subtopic);
8282
continue;
@@ -105,7 +105,9 @@ export class Docs {
105105
// Commands within the sub topic
106106
const filenames: string[] = [];
107107
for (const command of subtopicOrCommand) {
108-
const commandMeta = this.resolveCommandMeta(ensureString(command.id));
108+
const fullTopic = ensureString(command.id).replace(/:\w+$/, '');
109+
const commandsInFullTopic = subtopicOrCommand.filter(cmd => ensureString(cmd.id).indexOf(fullTopic) === 0);
110+
const commandMeta = this.resolveCommandMeta(ensureString(command.id), command, commandsInFullTopic.length);
109111

110112
filenames.push(await this.populateCommand(topic, subtopic, command, commandMeta));
111113
}
@@ -198,7 +200,7 @@ export class Docs {
198200
}
199201
}
200202

201-
private resolveCommandMeta(commandId: string) {
203+
private resolveCommandMeta(commandId: string, command, commandsInTopic: number) {
202204
const commandMeta: JsonMap = {};
203205
// Remove top level topic, since the topic meta is already for that topic
204206
const commandParts = commandId.split(':');
@@ -221,7 +223,15 @@ export class Docs {
221223
// This means there wasn't meta information going all the way down to the command, which is ok.
222224
return commandMeta;
223225
} else {
224-
events.emit('warning', `subtopic "${part}" meta not found for command ${commandId}`);
226+
if (commandsInTopic !== 1) {
227+
events.emit('warning', `subtopic "${part}" meta not found for command ${commandId}`);
228+
} else {
229+
// Since there is no command meta, just use the command description since that is what oclif does.
230+
if (!commandMeta.description) {
231+
commandMeta.description = command.description;
232+
commandMeta.longDescription = command.longDescription;
233+
}
234+
}
225235
}
226236
}
227237
return commandMeta;

0 commit comments

Comments
 (0)