swc/crates/swc_bundler/tests/.cache/deno/ea78e7fb0bcf6549a37d4d10feb27e4a7a2487ce.ts
2021-11-09 20:42:49 +09:00

45 lines
947 B
TypeScript

// Loaded from https://deno.land/x/args@1.0.7/help.ts
import {
makeIndentN,
InitMap,
} from "./utils.ts";
import {
Command,
CommandHelp,
} from "./command-types.ts";
class HelpCategories extends InitMap<string, CommandHelp[]> {
protected init(): CommandHelp[] {
return [];
}
}
export function* helpLines(
command: Command<any, any>,
cmdPath: readonly string[],
): Generator<string, void, unknown> {
const catMap = new HelpCategories();
for (const item of command.help(cmdPath)) {
catMap.get(item.category).push(item);
}
for (const [category, items] of catMap) {
yield category + ":";
for (const { title, description } of items) {
yield* makeIndentN(title, 2);
if (description) yield* makeIndentN(description, 4);
}
}
}
export const help = (
command: Command<any, any>,
cmdPath: readonly string[],
): string => [...helpLines(command, cmdPath)].join("\n");
export default help;