Skip to content

Commit 09aa49f

Browse files
committed
collapsed global flags + add .type ?? .choices
1 parent 2826090 commit 09aa49f

File tree

2 files changed

+63
-36
lines changed

2 files changed

+63
-36
lines changed

src/components/WranglerArg.astro

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
import { z } from "astro:schema";
3+
import { marked } from "marked";
4+
5+
import Type from "./Type.astro";
6+
import MetaInfo from "./MetaInfo.astro";
7+
8+
const props = z.object({
9+
key: z.string(),
10+
definition: z.custom<any>(),
11+
});
12+
13+
const { key, definition } = props.parse(Astro.props);
14+
15+
const type = definition.type ?? definition.choices;
16+
const description = definition.description ?? definition.describe;
17+
const required = definition.demandOption;
18+
const defaultValue = definition.default;
19+
const alias = definition.alias;
20+
const positional = definition.positionalArgs?.includes(key);
21+
22+
const name = positional ? `[${key.toUpperCase()}]` : `--${key}`;
23+
24+
let typeText;
25+
if (Array.isArray(type)) {
26+
typeText = type.map((t) => `"${t}"`).join(" | ");
27+
} else {
28+
typeText = type;
29+
}
30+
31+
let aliasText;
32+
if (alias) {
33+
if (Array.isArray(alias)) {
34+
aliasText = `aliases: --${alias.join(", --")}`;
35+
} else {
36+
aliasText = `alias: --${alias}`;
37+
}
38+
}
39+
---
40+
41+
<li>
42+
<code>{name}</code>
43+
<Type text={typeText} />{" "}
44+
{aliasText && <MetaInfo text={aliasText} />}
45+
{required && <MetaInfo text="required" />}
46+
{defaultValue !== undefined && <MetaInfo text={`default: ${defaultValue}`} />}
47+
<Fragment set:html={marked.parse(description)} />
48+
</li>

src/components/WranglerCommand.astro

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import { z } from "astro:schema";
33
import { experimental_getWranglerCommands } from "wrangler";
44
import AnchorHeading from "./AnchorHeading.astro";
5-
import Type from "./Type.astro";
65
import { PackageManagers } from "starlight-package-managers";
7-
import MetaInfo from "./MetaInfo.astro";
6+
import WranglerArg from "./WranglerArg.astro";
7+
import Details from "./Details.astro";
88
99
function getCommand(path: string) {
1010
const segments = path.trim().split(/\s+/);
@@ -41,10 +41,6 @@ if (!definition.args) {
4141
4242
const { globalFlags } = experimental_getWranglerCommands();
4343
44-
const args = Object.entries(definition.args).concat(
45-
Object.entries(globalFlags as unknown as typeof definition.args),
46-
);
47-
4844
const positionals = definition.positionalArgs
4945
?.map((p) => `[${p.toUpperCase()}]`)
5046
.join(" ");
@@ -60,37 +56,20 @@ const positionals = definition.positionalArgs
6056

6157
<ul>
6258
{
63-
args
64-
.filter(([_, value]) => !value.hidden && value.type !== undefined)
59+
Object.entries(definition.args)
60+
.filter(([_, value]) => !value.hidden)
6561
.map(([key, value]) => {
66-
const description = value.description ?? value.describe;
67-
const required = value.demandOption;
68-
const defaultValue = value.default;
69-
const alias = value.alias;
70-
const positional = definition.positionalArgs?.includes(key);
71-
72-
const name = positional ? `[${key.toUpperCase()}]` : `--${key}`;
73-
74-
let aliasText;
75-
if (alias) {
76-
if (Array.isArray(alias)) {
77-
aliasText = `aliases: --${alias.join(", --")}`;
78-
} else {
79-
aliasText = `alias: --${alias}`;
80-
}
81-
}
82-
83-
return (
84-
<li>
85-
<code>{name}</code> <Type text={value.type} />{" "}
86-
{aliasText && <MetaInfo text={aliasText} />}
87-
{required && <MetaInfo text="required" />}
88-
{defaultValue !== undefined && (
89-
<MetaInfo text={`default: ${defaultValue}`} />
90-
)}
91-
<p>{description}</p>
92-
</li>
93-
);
62+
return <WranglerArg key={key} definition={value} />;
9463
})
9564
}
9665
</ul>
66+
67+
<Details header="Global flags">
68+
<ul>
69+
{
70+
Object.entries(globalFlags).map(([key, value]) => {
71+
return <WranglerArg key={key} definition={value} />;
72+
})
73+
}
74+
</ul>
75+
</Details>

0 commit comments

Comments
 (0)