Skip to content

Commit

Permalink
fix: fix readme generator (#17)
Browse files Browse the repository at this point in the history
* fix: strip ansi from markdown gen

* fix: fix context stub in zcli json
  • Loading branch information
jaredLunde authored Feb 28, 2023
1 parent 86c668a commit 5677211
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 9 additions & 5 deletions zcli-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ZcliJsonCommand,
ZcliJsonFlag,
} from "./zcli-json.ts";
import { colors } from "./fmt.ts";

export async function zcliDoc<
Context extends {
Expand Down Expand Up @@ -63,7 +64,10 @@ function tableOfContents(

return `
| [**\`${name}\`**](#${formatMarkdownHeaderFragment(`$ ${name}`)}) | ${
(command.summary || command.description).replace("\n", " ")
(colors.stripColor(command.summary || command.description)).replace(
"\n",
" ",
)
} |
${
command.commands.filter(ignoreFilter(config, path)).map((cmd) =>
Expand Down Expand Up @@ -100,13 +104,13 @@ function commandToMarkdown(
## \`$ ${[...path, name].join(" ")}\`
${description || summary}
${colors.stripColor(description || summary)}
${
!args?.items.length ? "" : `
### Arguments
${args.description || args.summary || ""}
${colors.stripColor(args.description || args.summary || "")}
| Type | Variadic? | Description |
| ---- | --------- | ------------ |
Expand Down Expand Up @@ -171,14 +175,14 @@ function flagToMarkdown(flag: ZcliJsonFlag): string {
return `| ${formatFlagName(flag)} | \`${jsonSchemaToString(schema)}\` | ${
required ? "Yes" : "No"
} | ${defaultValue ? `\`${JSON.stringify(defaultValue)}\`` : ""} | ${
(description || summary || "").replace("\n", " ")
colors.stripColor(description || summary || "").replace("\n", " ")
} |`;
}

function argumentToMarkdown(arg: ZcliJsonArgument): string {
return `| \`${jsonSchemaToString(arg.schema)}\` | ${
arg.variadic ? "Yes" : "No"
} | ${arg.summary.replace("\n", " ")} |`;
} | ${colors.stripColor(arg.summary).replace("\n", " ")} |`;
}

function formatFlagName(flag: ZcliJsonFlag): string {
Expand Down
10 changes: 10 additions & 0 deletions zcli-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,22 @@ export async function zcliJson<
}),
})
.run(function ({ args, flags, ctx }) {
ctx = { ...ctx };
// @ts-expect-error: it's fine
ctx.root = root;
// @ts-expect-error: it's fine
ctx.path = [root.name];

function generateCommand(
command: Command<any, any, any>,
): ZcliJsonCommand {
ctx = { ...ctx };

if (command !== root) {
// @ts-expect-error: all good
ctx.path = [...ctx.path, command.name];
}

const commands: ZcliJsonCommand[] = [];

for (
Expand Down

0 comments on commit 5677211

Please sign in to comment.