Skip to content

Commit

Permalink
fix(@angular/cli): remove JSON serialized description from help output
Browse files Browse the repository at this point in the history
With this change we remove the JSON serialized description from the help output and also align the description properties between commands and subcommands.
  • Loading branch information
alan-agius4 committed Mar 10, 2022
1 parent df6ec4d commit c0ca876
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions packages/angular/cli/src/command-builder/utilities/json-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,6 @@
import yargs from 'yargs';
import { FullDescribe } from '../command-module';

export interface JsonHelp {
name: string;
shortDescription?: string;
command: string;
longDescription?: string;
longDescriptionRelativePath?: string;
options: JsonHelpOption[];
subcommands?: {
name: string;
description: string;
aliases: string[];
deprecated: string | boolean;
}[];
}

interface JsonHelpOption {
name: string;
type?: string;
Expand All @@ -36,6 +21,25 @@ interface JsonHelpOption {
description?: string;
}

interface JsonHelpDescription {
shortDescription?: string;
longDescription?: string;
longDescriptionRelativePath?: string;
}

interface JsonHelpSubcommand extends JsonHelpDescription {
name: string;
aliases: string[];
deprecated: string | boolean;
}

export interface JsonHelp extends JsonHelpDescription {
name: string;
command: string;
options: JsonHelpOption[];
subcommands?: JsonHelpSubcommand[];
}

export function jsonHelpUsage(): string {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const localYargs = yargs as any;
Expand Down Expand Up @@ -102,35 +106,15 @@ export function jsonHelpUsage(): string {
deprecated: string | boolean,
][]
)
.map(([name, description, _, aliases, deprecated]) => ({
.map(([name, rawDescription, _, aliases, deprecated]) => ({
name: name.split(' ', 1)[0],
command: name,
description,
...parseDescription(rawDescription),
aliases,
deprecated,
}))
.sort((a, b) => a.name.localeCompare(b.name));

const parseDescription = (rawDescription: string): Partial<JsonHelp> => {
try {
const {
longDescription,
describe: shortDescription,
longDescriptionRelativePath,
} = JSON.parse(rawDescription) as FullDescribe;

return {
shortDescription,
longDescriptionRelativePath,
longDescription,
};
} catch {
return {
shortDescription: rawDescription,
};
}
};

const [command, rawDescription] = usageInstance.getUsage()[0] ?? [];

const output: JsonHelp = {
Expand All @@ -143,3 +127,23 @@ export function jsonHelpUsage(): string {

return JSON.stringify(output, undefined, 2);
}

function parseDescription(rawDescription: string): JsonHelpDescription {
try {
const {
longDescription,
describe: shortDescription,
longDescriptionRelativePath,
} = JSON.parse(rawDescription) as FullDescribe;

return {
shortDescription,
longDescriptionRelativePath,
longDescription,
};
} catch {
return {
shortDescription: rawDescription,
};
}
}

0 comments on commit c0ca876

Please sign in to comment.