swc/bundler/tests/.cache/deno/ea78e7fb0bcf6549a37d4d10feb27e4a7a2487ce.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +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;