Skip to content

Commit 07f9092

Browse files
authored
feat: add state property (#206)
* feat: add state property * chore: code review
1 parent 3b9811b commit 07f9092

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

src/command.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export default abstract class Command {
4949
/** Hide the command from help? */
5050
static hidden: boolean
5151

52+
/** Mark the command as a given state (e.g. beta) in help? */
53+
static state?: string;
54+
5255
/**
5356
* An override string (or strings) for the default usage documentation.
5457
*/
@@ -111,7 +114,7 @@ export default abstract class Command {
111114

112115
private static globalFlags = {
113116
json: Flags.boolean({
114-
description: 'format output as json',
117+
description: 'Format output as json.',
115118
helpGroup: 'GLOBAL',
116119
}),
117120
}

src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ export async function toCached(c: Command.Class, plugin?: IPlugin): Promise<Comm
585585
pluginAlias: plugin && plugin.alias,
586586
pluginType: plugin && plugin.type,
587587
hidden: c.hidden,
588+
state: c.state,
588589
aliases: c.aliases || [],
589590
examples: c.examples || (c as any).example,
590591
flags,

src/help/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ export abstract class HelpBase extends HelpFormatter {
3939
* Show help, used in multi-command CLIs
4040
* @param args passed into your command, useful for determining which type of help to display
4141
*/
42-
public abstract async showHelp(argv: string[]): Promise<void>;
42+
public abstract showHelp(argv: string[]): Promise<void>;
4343

4444
/**
4545
* Show help for an individual command
4646
* @param command
4747
* @param topics
4848
*/
49-
public abstract async showCommandHelp(command: Interfaces.Command, topics: Interfaces.Topic[]): Promise<void>;
49+
public abstract showCommandHelp(command: Interfaces.Command, topics: Interfaces.Topic[]): Promise<void>;
5050
}
5151

5252
export class Help extends HelpBase {
@@ -108,7 +108,7 @@ export class Help extends HelpBase {
108108
}
109109

110110
const topic = this.config.findTopic(subject)
111-
if (topic) {
111+
if (topic) {
112112
await this.showTopicHelp(topic)
113113
return
114114
}
@@ -122,6 +122,10 @@ export class Help extends HelpBase {
122122

123123
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1)
124124
const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1)
125+
const plugin = this.config.plugins.find(p => p.name === command.pluginName)
126+
127+
const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state
128+
if (state) console.log(`This command is in ${state}.\n`)
125129

126130
const summary = this.summary(command)
127131
if (summary) console.log(summary + '\n')
@@ -143,6 +147,8 @@ export class Help extends HelpBase {
143147
let rootTopics = this.sortedTopics
144148
let rootCommands = this.sortedCommands
145149

150+
const state = this.config.pjson?.oclif?.state
151+
if (state) console.log(`${this.config.bin} is in ${state}.\n`)
146152
console.log(this.formatRoot())
147153
console.log('')
148154

@@ -170,6 +176,9 @@ export class Help extends HelpBase {
170176
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1)
171177
const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1)
172178

179+
const state = this.config.pjson?.oclif?.state
180+
if (state) console.log(`This topic is in ${state}.\n`)
181+
173182
console.log(this.formatTopic(topic))
174183

175184
if (subTopics.length > 0) {

src/interfaces/command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export interface CommandProps {
1313
/** Hide the command from help? */
1414
hidden: boolean;
1515

16+
/** Mark the command as a given state (e.g. beta) in help? */
17+
state?: string;
18+
1619
/** An array of aliases for this command. */
1720
aliases: string[];
1821

src/interfaces/pjson.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export namespace PJSON {
4545
};
4646
additionalHelpFlags?: string[];
4747
additionalVersionFlags?: string[];
48+
state?: string;
4849
};
4950
}
5051

test/help/format-command.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ FLAGS
8181
newliney
8282
8383
GLOBAL FLAGS
84-
--json format output as json
84+
--json Format output as json.
8585
8686
DESCRIPTION
8787
first line
@@ -139,7 +139,7 @@ FLAGS
139139
newliney
140140
141141
GLOBAL FLAGS
142-
--json format output as json
142+
--json Format output as json.
143143
144144
DESCRIPTION
145145
description of apps:create
@@ -199,7 +199,7 @@ FLAGS
199199
newliney
200200
201201
GLOBAL FLAGS
202-
--json format output as json
202+
--json Format output as json.
203203
204204
DESCRIPTION
205205
description of apps:create
@@ -261,7 +261,7 @@ FLAGS
261261
--force forces
262262
263263
GLOBAL FLAGS
264-
--json format output as json
264+
--json Format output as json.
265265
266266
DESCRIPTION
267267
description of apps:create

0 commit comments

Comments
 (0)