Skip to content

Commit

Permalink
feat: add state property (#206)
Browse files Browse the repository at this point in the history
* feat: add state property

* chore: code review
  • Loading branch information
mdonnalley committed Aug 3, 2021
1 parent 3b9811b commit 07f9092
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/command.ts
Expand Up @@ -49,6 +49,9 @@ export default abstract class Command {
/** Hide the command from help? */
static hidden: boolean

/** Mark the command as a given state (e.g. beta) in help? */
static state?: string;

/**
* An override string (or strings) for the default usage documentation.
*/
Expand Down Expand Up @@ -111,7 +114,7 @@ export default abstract class Command {

private static globalFlags = {
json: Flags.boolean({
description: 'format output as json',
description: 'Format output as json.',
helpGroup: 'GLOBAL',
}),
}
Expand Down
1 change: 1 addition & 0 deletions src/config/config.ts
Expand Up @@ -585,6 +585,7 @@ export async function toCached(c: Command.Class, plugin?: IPlugin): Promise<Comm
pluginAlias: plugin && plugin.alias,
pluginType: plugin && plugin.type,
hidden: c.hidden,
state: c.state,
aliases: c.aliases || [],
examples: c.examples || (c as any).example,
flags,
Expand Down
15 changes: 12 additions & 3 deletions src/help/index.ts
Expand Up @@ -39,14 +39,14 @@ export abstract class HelpBase extends HelpFormatter {
* Show help, used in multi-command CLIs
* @param args passed into your command, useful for determining which type of help to display
*/
public abstract async showHelp(argv: string[]): Promise<void>;
public abstract showHelp(argv: string[]): Promise<void>;

/**
* Show help for an individual command
* @param command
* @param topics
*/
public abstract async showCommandHelp(command: Interfaces.Command, topics: Interfaces.Topic[]): Promise<void>;
public abstract showCommandHelp(command: Interfaces.Command, topics: Interfaces.Topic[]): Promise<void>;
}

export class Help extends HelpBase {
Expand Down Expand Up @@ -108,7 +108,7 @@ export class Help extends HelpBase {
}

const topic = this.config.findTopic(subject)
if (topic) {
if (topic) {
await this.showTopicHelp(topic)
return
}
Expand All @@ -122,6 +122,10 @@ export class Help extends HelpBase {

const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1)
const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1)
const plugin = this.config.plugins.find(p => p.name === command.pluginName)

const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state
if (state) console.log(`This command is in ${state}.\n`)

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

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

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

const state = this.config.pjson?.oclif?.state
if (state) console.log(`This topic is in ${state}.\n`)

console.log(this.formatTopic(topic))

if (subTopics.length > 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/command.ts
Expand Up @@ -13,6 +13,9 @@ export interface CommandProps {
/** Hide the command from help? */
hidden: boolean;

/** Mark the command as a given state (e.g. beta) in help? */
state?: string;

/** An array of aliases for this command. */
aliases: string[];

Expand Down
1 change: 1 addition & 0 deletions src/interfaces/pjson.ts
Expand Up @@ -45,6 +45,7 @@ export namespace PJSON {
};
additionalHelpFlags?: string[];
additionalVersionFlags?: string[];
state?: string;
};
}

Expand Down
8 changes: 4 additions & 4 deletions test/help/format-command.test.ts
Expand Up @@ -81,7 +81,7 @@ FLAGS
newliney
GLOBAL FLAGS
--json format output as json
--json Format output as json.
DESCRIPTION
first line
Expand Down Expand Up @@ -139,7 +139,7 @@ FLAGS
newliney
GLOBAL FLAGS
--json format output as json
--json Format output as json.
DESCRIPTION
description of apps:create
Expand Down Expand Up @@ -199,7 +199,7 @@ FLAGS
newliney
GLOBAL FLAGS
--json format output as json
--json Format output as json.
DESCRIPTION
description of apps:create
Expand Down Expand Up @@ -261,7 +261,7 @@ FLAGS
--force forces
GLOBAL FLAGS
--json format output as json
--json Format output as json.
DESCRIPTION
description of apps:create
Expand Down

0 comments on commit 07f9092

Please sign in to comment.