Skip to content

Commit 4e128cf

Browse files
committed
Add optional arguments below command
1 parent 1a95029 commit 4e128cf

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/components/WranglerCLI.astro

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
22
import { z } from "astro:schema";
33
import { PackageManagers } from "starlight-package-managers";
4-
import { getCommand } from "~/util/wrangler";
4+
import { commands, getCommand } from "~/util/wrangler";
5+
import WranglerArg from "./WranglerArg.astro";
6+
import Details from "./Details.astro";
57
68
function validateArg(value: any, expected: string): boolean {
79
if (Array.isArray(expected)) {
@@ -23,12 +25,15 @@ const props = z.object({
2325
command: z.string(),
2426
positionals: z.array(z.string()).optional(),
2527
flags: z.record(z.string(), z.any()).optional(),
28+
showArgs: z.boolean().default(false),
2629
});
2730
28-
const { command, positionals, flags } = props.parse(Astro.props);
31+
const { command, positionals, flags, showArgs } = props.parse(Astro.props);
2932
3033
const definition = getCommand(command);
3134
35+
const { globalFlags } = commands;
36+
3237
let args = [];
3338
3439
if (flags) {
@@ -72,3 +77,29 @@ if (positionals) {
7277
type="exec"
7378
args={`${command} ${args.join(" ")}`}
7479
/>
80+
81+
{
82+
showArgs && definition.args && (
83+
<Details header="Arguments">
84+
<p>
85+
<strong>Command flags</strong>
86+
</p>
87+
<ul>
88+
{Object.entries(definition.args)
89+
.filter(([_, value]) => !value.hidden)
90+
.map(([key, value]) => {
91+
return <WranglerArg key={key} definition={value} />;
92+
})}
93+
</ul>
94+
95+
<p>
96+
<strong>Global flags</strong>
97+
</p>
98+
<ul>
99+
{Object.entries(globalFlags).map(([key, value]) => {
100+
return <WranglerArg key={key} definition={value} />;
101+
})}
102+
</ul>
103+
</Details>
104+
)
105+
}

src/content/docs/style-guide/components/wrangler-cli.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This is generated using the Wrangler version in the [`cloudflare-docs` repositor
1212

1313
## Import
1414

15+
{/* prettier-ignore */}
1516
```mdx
1617
import { WranglerCLI } from "~/components";
1718
```
@@ -41,3 +42,6 @@ import { WranglerCLI } from "~/components";
4142

4243
- `flags` <Type text="Record<string, any>" />
4344
- Any named argument values, i.e `name: "my-worker"` for the optional `name` argument on `deploy`.
45+
46+
- `showArgs` <Type text="boolean" /> <MetaInfo text="default (false)" />
47+
- Show the available arguments in a [`Details` component](/style-guide/components/details/) below the command.

0 commit comments

Comments
 (0)