11---
22import { z } from " astro:schema" ;
33import { 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
68function 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
3033const definition = getCommand (command );
3134
35+ const { globalFlags } = commands ;
36+
3237let args = [];
3338
3439if (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+ }
0 commit comments