@shell-shock/preset-cli 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import { BannerFunctionDeclaration } from "./banner-function-declaration.mjs";
2
2
  import { VirtualCommandEntry } from "./virtual-command-entry.mjs";
3
- import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
3
+ import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
4
4
  import { For, Match, Show, Switch, code, computed } from "@alloy-js/core";
5
- import { ElseClause, ElseIfClause, IfStatement } from "@alloy-js/typescript";
5
+ import { ElseIfClause, IfStatement } from "@alloy-js/typescript";
6
6
  import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
7
7
  import { isDynamicPathSegment } from "@shell-shock/core/plugin-utils/context-helpers";
8
8
  import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
@@ -12,6 +12,7 @@ import { findFilePath, relativePath } from "@stryke/path/find";
12
12
  import { joinPaths } from "@stryke/path/join";
13
13
  import { replaceExtension } from "@stryke/path/replace";
14
14
  import { camelCase } from "@stryke/string-format/camel-case";
15
+ import { lowerCaseFirst } from "@stryke/string-format/lower-case-first";
15
16
  import { pascalCase } from "@stryke/string-format/pascal-case";
16
17
  import defu from "defu";
17
18
 
@@ -45,7 +46,6 @@ function CommandEntry(props) {
45
46
  return defu(builtinImports ?? {}, {
46
47
  env: [
47
48
  "env",
48
- "isCI",
49
49
  "isDevelopment",
50
50
  "isDebug"
51
51
  ],
@@ -60,15 +60,19 @@ function CommandEntry(props) {
60
60
  "splitText",
61
61
  "text",
62
62
  "confirm",
63
- "isCancel"
63
+ "isCancel",
64
+ "intro",
65
+ "outro"
64
66
  ],
65
67
  utils: [
66
- "getArgs",
68
+ "useApp",
69
+ "useArgs",
67
70
  "hasFlag",
68
71
  "isMinimal",
69
72
  "isInteractive",
73
+ "isHelp",
70
74
  "isUnicodeSupported",
71
- "internal_commandContextStore"
75
+ "internal_commandContext"
72
76
  ]
73
77
  });
74
78
  },
@@ -85,41 +89,49 @@ function CommandEntry(props) {
85
89
  get children() {
86
90
  return createComponent(CommandValidationLogic, { command });
87
91
  }
88
- }), createComponent(ElseClause, { get children() {
89
- return [
90
- createIntrinsic("hbr", {}),
91
- createComponent(For, {
92
- get each() {
93
- return Object.values(command.options ?? {});
94
- },
95
- doubleHardline: true,
96
- children: (option) => [createComponent(Show, {
97
- get when() {
98
- return !option.optional;
92
+ }), createComponent(ElseIfClause, {
93
+ get condition() {
94
+ return code`!isHelp && (${Object.values(command.options ?? {}).filter((option) => !option.optional).map((option) => (option.kind === ReflectionKind.string || option.kind === ReflectionKind.number) && option.variadic ? `(!options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} || options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}.length === 0)` : `options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} === undefined`).join(" || ")}${Object.values(command.options ?? {}).filter((option) => !option.optional).length > 0 && Object.values(command.arguments ?? {}).filter((argument) => !argument.optional).length > 0 ? " || " : ""}${Object.values(command.arguments ?? {}).filter((argument) => !argument.optional).map((argument) => (argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number) && argument.variadic ? `(!${camelCase(argument.name)} || ${camelCase(argument.name)}.length === 0)` : `${camelCase(argument.name)} === undefined`).join(" || ")}) `;
95
+ },
96
+ get children() {
97
+ return [
98
+ code`writeLine("");
99
+
100
+ intro("Select required input parameters"); `,
101
+ createIntrinsic("hbr", {}),
102
+ createIntrinsic("hbr", {}),
103
+ createComponent(For, {
104
+ get each() {
105
+ return Object.values(command.options ?? {});
99
106
  },
100
- get children() {
101
- return [createComponent(IfStatement, {
102
- get condition() {
103
- return code`!options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}`;
104
- },
105
- get children() {
106
- return createComponent(Switch, { get children() {
107
- return [createComponent(Match, {
108
- get when() {
109
- return option.kind === ReflectionKind.string || option.kind === ReflectionKind.number;
110
- },
111
- get children() {
112
- return code`
107
+ doubleHardline: true,
108
+ children: (option) => [createComponent(Show, {
109
+ get when() {
110
+ return !option.optional;
111
+ },
112
+ get children() {
113
+ return [createComponent(IfStatement, {
114
+ get condition() {
115
+ return code`!options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}`;
116
+ },
117
+ get children() {
118
+ return createComponent(Switch, { get children() {
119
+ return [createComponent(Match, {
120
+ get when() {
121
+ return option.kind === ReflectionKind.string || option.kind === ReflectionKind.number;
122
+ },
123
+ get children() {
124
+ return code`
113
125
  const value = await text({
114
- message: 'Please provide a value for the ${option.title} option:',
115
- validate(value) {
116
- if (isCancel(value)) {
126
+ message: 'Please provide a${option.kind === ReflectionKind.number ? " numeric" : ""} value for the "${option.name}" option${option.description ? ` (${lowerCaseFirst(option.description).replace(/\.+$/, "")})` : ""}:',
127
+ validate(val) {
128
+ if (isCancel(val)) {
117
129
  return true;
118
130
  }
119
- if (!value || value.trim() === "") {
120
- return "A value is required for this option";
131
+ if (!val || val.trim() === "") {
132
+ return "A value must be provided for this option";
121
133
  }
122
- ${option.kind === ReflectionKind.number ? `if (Number.isNaN(Number(value))) {
134
+ ${option.kind === ReflectionKind.number ? `if (Number.isNaN(Number(val))) {
123
135
  return "The value provided must be a valid number";
124
136
  }` : ""}
125
137
  return undefined;
@@ -131,45 +143,45 @@ function CommandEntry(props) {
131
143
 
132
144
  options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} = ${option.kind === ReflectionKind.number ? `Number(value)` : "value"};
133
145
  `;
134
- }
135
- }), createComponent(Match, {
136
- get when() {
137
- return option.kind === ReflectionKind.boolean;
138
- },
139
- get children() {
140
- return code`
146
+ }
147
+ }), createComponent(Match, {
148
+ get when() {
149
+ return option.kind === ReflectionKind.boolean;
150
+ },
151
+ get children() {
152
+ return code`
141
153
  options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} = await confirm({
142
- message: 'Please select a value for the ${option.title} option:'
154
+ message: 'Please select a value for the "${option.name}" option${option.description ? ` (${lowerCaseFirst(option.description).replace(/\.+$/, "")})` : ""}:'
143
155
  });
144
156
  `;
145
- }
146
- })];
147
- } });
148
- }
149
- }), createComponent(Show, {
150
- get when() {
151
- return (option.kind === ReflectionKind.string || option.kind === ReflectionKind.number) && option.variadic;
152
- },
153
- get children() {
154
- return createComponent(ElseIfClause, {
155
- get condition() {
156
- return code`options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}.length === 0`;
157
- },
158
- get children() {
159
- return code`
157
+ }
158
+ })];
159
+ } });
160
+ }
161
+ }), createComponent(Show, {
162
+ get when() {
163
+ return (option.kind === ReflectionKind.string || option.kind === ReflectionKind.number) && option.variadic;
164
+ },
165
+ get children() {
166
+ return createComponent(ElseIfClause, {
167
+ get condition() {
168
+ return code`options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}.length === 0`;
169
+ },
170
+ get children() {
171
+ return code`
160
172
  const value = await text({
161
- message: 'Please provide one or more values for the ${option.title} option (values are separated by a "," character):',
162
- validate(value) {
163
- if (isCancel(value)) {
173
+ message: 'Please provide one or more${option.kind === ReflectionKind.number ? " numeric" : ""} values for the "${option.name}" option${option.description ? ` (${lowerCaseFirst(option.description).replace(/\.+$/, "")})` : ""} - values are separated by a "," character:',
174
+ validate(val) {
175
+ if (isCancel(val)) {
164
176
  return true;
165
177
  }
166
- if (!value || value.trim() === "") {
167
- return "A value is required for this option";
178
+ if (!val || val.trim() === "") {
179
+ return "A value must be provided for this option";
168
180
  }
169
- if (value.split(",").map(value => value.trim()).filter(Boolean).length === 0) {
170
- return "At least one value is required for this option";
181
+ if (val.split(",").map(v => v.trim()).filter(Boolean).length === 0) {
182
+ return "At least one value must be provided for this option";
171
183
  }
172
- ${option.kind === ReflectionKind.number ? `const invalidIndex = value.split(",").map(value => value.trim()).filter(Boolean).findIndex(value => Number.isNaN(Number(value));
184
+ ${option.kind === ReflectionKind.number ? `const invalidIndex = val.split(",").map(v => v.trim()).filter(Boolean).findIndex(v => Number.isNaN(Number(v));
173
185
  if (invalidIndex !== -1) {
174
186
  return \`Invalid numeric value provided for item #\${invalidIndex + 1} - all provided items must be a valid number\`;
175
187
  } ` : ""}
@@ -182,48 +194,48 @@ function CommandEntry(props) {
182
194
 
183
195
  options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} = value.split(",").map(value => value.trim()).filter(Boolean)${option.kind === ReflectionKind.number ? `.map(Number)` : ""} ;
184
196
  `;
185
- }
186
- });
187
- }
188
- })];
189
- }
190
- })]
191
- }),
192
- createIntrinsic("hbr", {}),
193
- createIntrinsic("hbr", {}),
194
- createComponent(For, {
195
- get each() {
196
- return command.arguments;
197
- },
198
- doubleHardline: true,
199
- children: (argument) => [createComponent(Show, {
200
- get when() {
201
- return !argument.optional;
197
+ }
198
+ });
199
+ }
200
+ })];
201
+ }
202
+ })]
203
+ }),
204
+ createIntrinsic("hbr", {}),
205
+ createIntrinsic("hbr", {}),
206
+ createComponent(For, {
207
+ get each() {
208
+ return command.arguments;
202
209
  },
203
- get children() {
204
- return [createComponent(IfStatement, {
205
- get condition() {
206
- return code`!${camelCase(argument.name)}`;
207
- },
208
- get children() {
209
- return createComponent(Switch, { get children() {
210
- return [createComponent(Match, {
211
- get when() {
212
- return argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number;
213
- },
214
- get children() {
215
- return code`
210
+ doubleHardline: true,
211
+ children: (argument) => [createComponent(Show, {
212
+ get when() {
213
+ return !argument.optional;
214
+ },
215
+ get children() {
216
+ return [createComponent(IfStatement, {
217
+ get condition() {
218
+ return code`!${camelCase(argument.name)}`;
219
+ },
220
+ get children() {
221
+ return createComponent(Switch, { get children() {
222
+ return [createComponent(Match, {
223
+ get when() {
224
+ return argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number;
225
+ },
226
+ get children() {
227
+ return code`
216
228
  const value = await text({
217
- message: 'Please provide a value for the ${argument.title} positional argument:',
218
- validate(value) {
219
- if (isCancel(value)) {
229
+ message: 'Please provide a${argument.kind === ReflectionKind.number ? " numeric" : ""} value for the "${argument.name}" argument${argument.description ? ` (${lowerCaseFirst(argument.description).replace(/\.+$/, "")})` : ""}:',
230
+ validate(val) {
231
+ if (isCancel(val)) {
220
232
  return true;
221
233
  }
222
- if (!value || value.trim() === "") {
223
- return "A value is required for this positional argument";
234
+ if (!val || val.trim() === "") {
235
+ return "A value must be provided for this argument";
224
236
  }
225
- ${argument.kind === ReflectionKind.number ? `if (Number.isNaN(Number(value))) {
226
- return "The value provided must be a valid number";
237
+ ${argument.kind === ReflectionKind.number ? `if (Number.isNaN(Number(val))) {
238
+ return "The provided value must be a valid number";
227
239
  }` : ""}
228
240
  return undefined;
229
241
  }
@@ -234,45 +246,45 @@ function CommandEntry(props) {
234
246
 
235
247
  ${camelCase(argument.name)} = ${argument.kind === ReflectionKind.number ? `Number(value)` : "value"};
236
248
  `;
237
- }
238
- }), createComponent(Match, {
239
- get when() {
240
- return argument.kind === ReflectionKind.boolean;
241
- },
242
- get children() {
243
- return code`
249
+ }
250
+ }), createComponent(Match, {
251
+ get when() {
252
+ return argument.kind === ReflectionKind.boolean;
253
+ },
254
+ get children() {
255
+ return code`
244
256
  ${camelCase(argument.name)} = await confirm({
245
- message: 'Please select a value for the ${argument.title} positional argument:'
257
+ message: 'Please select a value for the "${argument.name}" argument${argument.description ? ` (${lowerCaseFirst(argument.description).replace(/\.+$/, "")})` : ""}:'
246
258
  });
247
259
  `;
248
- }
249
- })];
250
- } });
251
- }
252
- }), createComponent(Show, {
253
- get when() {
254
- return (argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number) && argument.variadic;
255
- },
256
- get children() {
257
- return createComponent(ElseIfClause, {
258
- get condition() {
259
- return code`${camelCase(argument.name)}.length === 0`;
260
- },
261
- get children() {
262
- return code`
260
+ }
261
+ })];
262
+ } });
263
+ }
264
+ }), createComponent(Show, {
265
+ get when() {
266
+ return (argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number) && argument.variadic;
267
+ },
268
+ get children() {
269
+ return createComponent(ElseIfClause, {
270
+ get condition() {
271
+ return code`${camelCase(argument.name)}.length === 0`;
272
+ },
273
+ get children() {
274
+ return code`
263
275
  const value = await text({
264
- message: 'Please provide one or more values for the ${argument.title} option (values are separated by a "," character):',
265
- validate(value) {
266
- if (isCancel(value)) {
276
+ message: 'Please provide one or more${argument.kind === ReflectionKind.number ? " numeric" : ""} values for the "${argument.name}" argument${argument.description ? ` (${lowerCaseFirst(argument.description).replace(/\.+$/, "")})` : ""} - values are separated by a "," character:',
277
+ validate(val) {
278
+ if (isCancel(val)) {
267
279
  return true;
268
280
  }
269
- if (!value || value.trim() === "") {
270
- return "A value is required for this option";
281
+ if (!val || val.trim() === "") {
282
+ return "A value must be provided for this argument";
271
283
  }
272
- if (value.split(",").map(value => value.trim()).filter(Boolean).length === 0) {
273
- return "At least one value is required for this option";
284
+ if (val.split(",").map(v => v.trim()).filter(Boolean).length === 0) {
285
+ return "At least one value must be provided for this argument";
274
286
  }
275
- ${argument.kind === ReflectionKind.number ? `const invalidIndex = value.split(",").map(value => value.trim()).filter(Boolean).findIndex(value => Number.isNaN(Number(value));
287
+ ${argument.kind === ReflectionKind.number ? `const invalidIndex = val.split(",").map(v => v.trim()).filter(Boolean).findIndex(v => Number.isNaN(Number(v));
276
288
  if (invalidIndex !== -1) {
277
289
  return \`Invalid numeric value provided for item #\${invalidIndex + 1} - all provided items must be a valid number\`;
278
290
  } ` : ""}
@@ -286,15 +298,21 @@ function CommandEntry(props) {
286
298
 
287
299
  ${camelCase(argument.name)} = value.split(",").map(value => value.trim()).filter(Boolean)${argument.kind === ReflectionKind.number ? `.map(Number)` : ""} ;
288
300
  `;
289
- }
290
- });
291
- }
292
- })];
293
- }
294
- })]
295
- })
296
- ];
297
- } })];
301
+ }
302
+ });
303
+ }
304
+ })];
305
+ }
306
+ })]
307
+ }),
308
+ code`outro("Completed providing all required input parameters");
309
+
310
+ writeLine(""); `,
311
+ createIntrinsic("hbr", {}),
312
+ createIntrinsic("hbr", {})
313
+ ];
314
+ }
315
+ })];
298
316
  }
299
317
  })
300
318
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"command-entry.mjs","names":["code","computed","For","Match","Show","Switch","ElseClause","ElseIfClause","IfStatement","ReflectionKind","usePowerlines","EntryFile","isDynamicPathSegment","CommandHandlerDeclaration","CommandValidationLogic","findFilePath","relativePath","joinPaths","replaceExtension","camelCase","pascalCase","defu","BannerFunctionDeclaration","VirtualCommandEntry","CommandEntry","props","command","imports","builtinImports","rest","context","filePath","segments","filter","segment","join","commandSourcePath","entryPath","value","entry","input","file","typeDefinition","output","id","_$createComponent","_$mergeProps","path","name","prompts","env","console","utils","children","_$createIntrinsic","condition","each","Object","values","options","doubleHardline","option","when","optional","includes","kind","string","number","title","boolean","variadic","arguments","argument","child","isVirtual","fallback"],"sources":["../../src/components/command-entry.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, computed, For, Match, Show, Switch } from \"@alloy-js/core\";\nimport { ElseClause, ElseIfClause, IfStatement } from \"@alloy-js/typescript\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { EntryFileProps } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { EntryFile } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { isDynamicPathSegment } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport type { CommandTree } from \"@shell-shock/core/types/command\";\nimport {\n CommandHandlerDeclaration,\n CommandValidationLogic\n} from \"@shell-shock/preset-script/components/command-entry\";\nimport { findFilePath, relativePath } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { CLIPresetContext } from \"../types/plugin\";\nimport { BannerFunctionDeclaration } from \"./banner-function-declaration\";\nimport { VirtualCommandEntry } from \"./virtual-command-entry\";\n\nexport interface CommandEntryProps extends Omit<\n EntryFileProps,\n \"path\" | \"typeDefinition\"\n> {\n command: CommandTree;\n}\n\n/**\n * The command entry point for the Shell Shock project.\n */\nexport function CommandEntry(props: CommandEntryProps) {\n const { command, imports, builtinImports, ...rest } = props;\n\n const context = usePowerlines<CLIPresetContext>();\n const filePath = computed(() =>\n joinPaths(\n command.segments\n .filter(segment => !isDynamicPathSegment(segment))\n .join(\"/\"),\n \"index.ts\"\n )\n );\n const commandSourcePath = computed(() =>\n replaceExtension(\n relativePath(\n joinPaths(context.entryPath, findFilePath(filePath.value)),\n command.entry.input?.file || command.entry.file\n )\n )\n );\n const typeDefinition = computed(() => ({\n ...command.entry,\n output: command.id\n }));\n\n return (\n <>\n <EntryFile\n {...rest}\n path={filePath.value}\n typeDefinition={typeDefinition.value}\n imports={defu(imports ?? {}, {\n [commandSourcePath.value]: `handle${pascalCase(command.name)}`,\n prompts: \"prompts\"\n })}\n builtinImports={defu(builtinImports ?? {}, {\n env: [\"env\", \"isCI\", \"isDevelopment\", \"isDebug\"],\n console: [\n \"debug\",\n \"warn\",\n \"error\",\n \"table\",\n \"colors\",\n \"stripAnsi\",\n \"writeLine\",\n \"splitText\",\n \"text\",\n \"confirm\",\n \"isCancel\"\n ],\n utils: [\n \"getArgs\",\n \"hasFlag\",\n \"isMinimal\",\n \"isInteractive\",\n \"isUnicodeSupported\",\n \"internal_commandContextStore\"\n ]\n })}>\n <BannerFunctionDeclaration command={command} />\n <hbr />\n <hbr />\n <CommandHandlerDeclaration command={command}>\n <IfStatement condition={code`!isInteractive`}>\n <CommandValidationLogic command={command} />\n </IfStatement>\n <ElseClause>\n <hbr />\n <For each={Object.values(command.options ?? {})} doubleHardline>\n {option => (\n <>\n <Show when={!option.optional}>\n <IfStatement\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }`}>\n <Switch>\n <Match\n when={\n option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number\n }>{code`\n const value = await text({\n message: 'Please provide a value for the ${option.title} option:',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this option\";\n }\n ${\n option.kind === ReflectionKind.number\n ? `if (Number.isNaN(Number(value))) {\n return \"The value provided must be a valid number\";\n }`\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = ${\n option.kind === ReflectionKind.number\n ? `Number(value)`\n : \"value\"\n };\n `}</Match>\n <Match\n when={option.kind === ReflectionKind.boolean}>{code`\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = await confirm({\n message: 'Please select a value for the ${option.title} option:'\n });\n `}</Match>\n </Switch>\n </IfStatement>\n <Show\n when={\n (option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number) &&\n option.variadic\n }>\n <ElseIfClause\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0`}>\n {code`\n const value = await text({\n message: 'Please provide one or more values for the ${\n option.title\n } option (values are separated by a \",\" character):',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this option\";\n }\n if (value.split(\",\").map(value => value.trim()).filter(Boolean).length === 0) {\n return \"At least one value is required for this option\";\n }\n ${\n option.kind === ReflectionKind.number\n ? `const invalidIndex = value.split(\",\").map(value => value.trim()).filter(Boolean).findIndex(value => Number.isNaN(Number(value));\n if (invalidIndex !== -1) {\n return \\`Invalid numeric value provided for item #\\${invalidIndex + 1} - all provided items must be a valid number\\`;\n } `\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = value.split(\",\").map(value => value.trim()).filter(Boolean)${\n option.kind === ReflectionKind.number\n ? `.map(Number)`\n : \"\"\n } ;\n `}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n <hbr />\n <hbr />\n <For each={command.arguments} doubleHardline>\n {argument => (\n <>\n <Show when={!argument.optional}>\n <IfStatement condition={code`!${camelCase(argument.name)}`}>\n <Switch>\n <Match\n when={\n argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number\n }>{code`\n const value = await text({\n message: 'Please provide a value for the ${argument.title} positional argument:',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this positional argument\";\n }\n ${\n argument.kind === ReflectionKind.number\n ? `if (Number.isNaN(Number(value))) {\n return \"The value provided must be a valid number\";\n }`\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n ${camelCase(argument.name)} = ${\n argument.kind === ReflectionKind.number\n ? `Number(value)`\n : \"value\"\n };\n `}</Match>\n <Match\n when={argument.kind === ReflectionKind.boolean}>{code`\n ${camelCase(argument.name)} = await confirm({\n message: 'Please select a value for the ${argument.title} positional argument:'\n });\n `}</Match>\n </Switch>\n </IfStatement>\n <Show\n when={\n (argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number) &&\n argument.variadic\n }>\n <ElseIfClause\n condition={code`${camelCase(argument.name)}.length === 0`}>\n {code`\n const value = await text({\n message: 'Please provide one or more values for the ${\n argument.title\n } option (values are separated by a \",\" character):',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this option\";\n }\n if (value.split(\",\").map(value => value.trim()).filter(Boolean).length === 0) {\n return \"At least one value is required for this option\";\n }\n ${\n argument.kind === ReflectionKind.number\n ? `const invalidIndex = value.split(\",\").map(value => value.trim()).filter(Boolean).findIndex(value => Number.isNaN(Number(value));\n if (invalidIndex !== -1) {\n return \\`Invalid numeric value provided for item #\\${invalidIndex + 1} - all provided items must be a valid number\\`;\n } `\n : \"\"\n }\n\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n ${camelCase(argument.name)} = value.split(\",\").map(value => value.trim()).filter(Boolean)${\n argument.kind === ReflectionKind.number\n ? `.map(Number)`\n : \"\"\n } ;\n `}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n </ElseClause>\n </CommandHandlerDeclaration>\n </EntryFile>\n <For each={Object.values(command.children)}>\n {child => (\n <Show\n when={child.isVirtual}\n fallback={<CommandEntry command={child} />}>\n <VirtualCommandEntry command={child} />\n </Show>\n )}\n </For>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgBwB,aAAaC,OAA0B;CACrD,MAAM,EAAEC,SAASC,SAASC,gBAAgB,GAAGC,SAASJ;CAEtD,MAAMK,UAAUpB,eAAiC;CACjD,MAAMqB,WAAW9B,eACfgB,UACES,QAAQM,SACLC,QAAOC,YAAW,CAACtB,qBAAqBsB,QAAQ,CAAC,CACjDC,KAAK,IAAI,EACZ,WAEJ,CAAC;CACD,MAAMC,oBAAoBnC,eACxBiB,iBACEF,aACEC,UAAUa,QAAQO,WAAWtB,aAAagB,SAASO,MAAM,CAAC,EAC1DZ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,OAAK,CAAA;;GAAA,CAAA;EAEtC,CAAA,CAAA"}
1
+ {"version":3,"file":"command-entry.mjs","names":["code","computed","For","Match","Show","Switch","ElseIfClause","IfStatement","ReflectionKind","usePowerlines","EntryFile","isDynamicPathSegment","CommandHandlerDeclaration","CommandValidationLogic","findFilePath","relativePath","joinPaths","replaceExtension","camelCase","lowerCaseFirst","pascalCase","defu","BannerFunctionDeclaration","VirtualCommandEntry","CommandEntry","props","command","imports","builtinImports","rest","context","filePath","segments","filter","segment","join","commandSourcePath","entryPath","value","entry","input","file","typeDefinition","output","id","_$createComponent","_$mergeProps","path","name","prompts","env","console","utils","children","_$createIntrinsic","condition","Object","values","options","option","optional","map","kind","string","number","variadic","includes","length","arguments","argument","each","doubleHardline","when","description","replace","boolean","child","isVirtual","fallback"],"sources":["../../src/components/command-entry.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, computed, For, Match, Show, Switch } from \"@alloy-js/core\";\nimport { ElseIfClause, IfStatement } from \"@alloy-js/typescript\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { EntryFileProps } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { EntryFile } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { isDynamicPathSegment } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport type { CommandTree } from \"@shell-shock/core/types/command\";\nimport {\n CommandHandlerDeclaration,\n CommandValidationLogic\n} from \"@shell-shock/preset-script/components/command-entry\";\nimport { findFilePath, relativePath } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { lowerCaseFirst } from \"@stryke/string-format/lower-case-first\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { CLIPresetContext } from \"../types/plugin\";\nimport { BannerFunctionDeclaration } from \"./banner-function-declaration\";\nimport { VirtualCommandEntry } from \"./virtual-command-entry\";\n\nexport interface CommandEntryProps extends Omit<\n EntryFileProps,\n \"path\" | \"typeDefinition\"\n> {\n command: CommandTree;\n}\n\n/**\n * The command entry point for the Shell Shock project.\n */\nexport function CommandEntry(props: CommandEntryProps) {\n const { command, imports, builtinImports, ...rest } = props;\n\n const context = usePowerlines<CLIPresetContext>();\n const filePath = computed(() =>\n joinPaths(\n command.segments\n .filter(segment => !isDynamicPathSegment(segment))\n .join(\"/\"),\n \"index.ts\"\n )\n );\n const commandSourcePath = computed(() =>\n replaceExtension(\n relativePath(\n joinPaths(context.entryPath, findFilePath(filePath.value)),\n command.entry.input?.file || command.entry.file\n )\n )\n );\n const typeDefinition = computed(() => ({\n ...command.entry,\n output: command.id\n }));\n\n return (\n <>\n <EntryFile\n {...rest}\n path={filePath.value}\n typeDefinition={typeDefinition.value}\n imports={defu(imports ?? {}, {\n [commandSourcePath.value]: `handle${pascalCase(command.name)}`,\n prompts: \"prompts\"\n })}\n builtinImports={defu(builtinImports ?? {}, {\n env: [\"env\", \"isDevelopment\", \"isDebug\"],\n console: [\n \"debug\",\n \"warn\",\n \"error\",\n \"table\",\n \"colors\",\n \"stripAnsi\",\n \"writeLine\",\n \"splitText\",\n \"text\",\n \"confirm\",\n \"isCancel\",\n \"intro\",\n \"outro\"\n ],\n utils: [\n \"useApp\",\n \"useArgs\",\n \"hasFlag\",\n \"isMinimal\",\n \"isInteractive\",\n \"isHelp\",\n \"isUnicodeSupported\",\n \"internal_commandContext\"\n ]\n })}>\n <BannerFunctionDeclaration command={command} />\n <hbr />\n <hbr />\n <CommandHandlerDeclaration command={command}>\n <IfStatement condition={code`!isInteractive`}>\n <CommandValidationLogic command={command} />\n </IfStatement>\n <ElseIfClause\n condition={code`!isHelp && (${Object.values(command.options ?? {})\n .filter(option => !option.optional)\n .map(option =>\n (option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number) &&\n option.variadic\n ? `(!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } || options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0)`\n : `options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } === undefined`\n )\n .join(\" || \")}${\n Object.values(command.options ?? {}).filter(\n option => !option.optional\n ).length > 0 &&\n Object.values(command.arguments ?? {}).filter(\n argument => !argument.optional\n ).length > 0\n ? \" || \"\n : \"\"\n }${Object.values(command.arguments ?? {})\n .filter(argument => !argument.optional)\n .map(argument =>\n (argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number) &&\n argument.variadic\n ? `(!${camelCase(\n argument.name\n )} || ${camelCase(argument.name)}.length === 0)`\n : `${camelCase(argument.name)} === undefined`\n )\n .join(\" || \")}) `}>\n {code`writeLine(\"\");\n\n intro(\"Select required input parameters\"); `}\n <hbr />\n <hbr />\n <For each={Object.values(command.options ?? {})} doubleHardline>\n {option => (\n <>\n <Show when={!option.optional}>\n <IfStatement\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }`}>\n <Switch>\n <Match\n when={\n option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number\n }>{code`\n const value = await text({\n message: 'Please provide a${\n option.kind === ReflectionKind.number\n ? \" numeric\"\n : \"\"\n } value for the \"${option.name}\" option${\n option.description\n ? ` (${lowerCaseFirst(\n option.description\n ).replace(/\\.+$/, \"\")})`\n : \"\"\n }:',\n validate(val) {\n if (isCancel(val)) {\n return true;\n }\n if (!val || val.trim() === \"\") {\n return \"A value must be provided for this option\";\n }\n ${\n option.kind === ReflectionKind.number\n ? `if (Number.isNaN(Number(val))) {\n return \"The value provided must be a valid number\";\n }`\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = ${\n option.kind === ReflectionKind.number\n ? `Number(value)`\n : \"value\"\n };\n `}</Match>\n <Match\n when={option.kind === ReflectionKind.boolean}>{code`\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = await confirm({\n message: 'Please select a value for the \"${\n option.name\n }\" option${\n option.description\n ? ` (${lowerCaseFirst(\n option.description\n ).replace(/\\.+$/, \"\")})`\n : \"\"\n }:'\n });\n `}</Match>\n </Switch>\n </IfStatement>\n <Show\n when={\n (option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number) &&\n option.variadic\n }>\n <ElseIfClause\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0`}>\n {code`\n const value = await text({\n message: 'Please provide one or more${\n option.kind === ReflectionKind.number\n ? \" numeric\"\n : \"\"\n } values for the \"${option.name}\" option${\n option.description\n ? ` (${lowerCaseFirst(\n option.description\n ).replace(/\\.+$/, \"\")})`\n : \"\"\n } - values are separated by a \",\" character:',\n validate(val) {\n if (isCancel(val)) {\n return true;\n }\n if (!val || val.trim() === \"\") {\n return \"A value must be provided for this option\";\n }\n if (val.split(\",\").map(v => v.trim()).filter(Boolean).length === 0) {\n return \"At least one value must be provided for this option\";\n }\n ${\n option.kind === ReflectionKind.number\n ? `const invalidIndex = val.split(\",\").map(v => v.trim()).filter(Boolean).findIndex(v => Number.isNaN(Number(v));\n if (invalidIndex !== -1) {\n return \\`Invalid numeric value provided for item #\\${invalidIndex + 1} - all provided items must be a valid number\\`;\n } `\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = value.split(\",\").map(value => value.trim()).filter(Boolean)${\n option.kind === ReflectionKind.number\n ? `.map(Number)`\n : \"\"\n } ;\n `}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n <hbr />\n <hbr />\n <For each={command.arguments} doubleHardline>\n {argument => (\n <>\n <Show when={!argument.optional}>\n <IfStatement condition={code`!${camelCase(argument.name)}`}>\n <Switch>\n <Match\n when={\n argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number\n }>{code`\n const value = await text({\n message: 'Please provide a${\n argument.kind === ReflectionKind.number\n ? \" numeric\"\n : \"\"\n } value for the \"${argument.name}\" argument${\n argument.description\n ? ` (${lowerCaseFirst(argument.description).replace(/\\.+$/, \"\")})`\n : \"\"\n }:',\n validate(val) {\n if (isCancel(val)) {\n return true;\n }\n if (!val || val.trim() === \"\") {\n return \"A value must be provided for this argument\";\n }\n ${\n argument.kind === ReflectionKind.number\n ? `if (Number.isNaN(Number(val))) {\n return \"The provided value must be a valid number\";\n }`\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n ${camelCase(argument.name)} = ${\n argument.kind === ReflectionKind.number\n ? `Number(value)`\n : \"value\"\n };\n `}</Match>\n <Match\n when={argument.kind === ReflectionKind.boolean}>{code`\n ${camelCase(argument.name)} = await confirm({\n message: 'Please select a value for the \"${argument.name}\" argument${\n argument.description\n ? ` (${lowerCaseFirst(argument.description).replace(/\\.+$/, \"\")})`\n : \"\"\n }:'\n });\n `}</Match>\n </Switch>\n </IfStatement>\n <Show\n when={\n (argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number) &&\n argument.variadic\n }>\n <ElseIfClause\n condition={code`${camelCase(argument.name)}.length === 0`}>\n {code`\n const value = await text({\n message: 'Please provide one or more${\n argument.kind === ReflectionKind.number\n ? \" numeric\"\n : \"\"\n } values for the \"${argument.name}\" argument${\n argument.description\n ? ` (${lowerCaseFirst(argument.description).replace(/\\.+$/, \"\")})`\n : \"\"\n } - values are separated by a \",\" character:',\n validate(val) {\n if (isCancel(val)) {\n return true;\n }\n if (!val || val.trim() === \"\") {\n return \"A value must be provided for this argument\";\n }\n if (val.split(\",\").map(v => v.trim()).filter(Boolean).length === 0) {\n return \"At least one value must be provided for this argument\";\n }\n ${\n argument.kind === ReflectionKind.number\n ? `const invalidIndex = val.split(\",\").map(v => v.trim()).filter(Boolean).findIndex(v => Number.isNaN(Number(v));\n if (invalidIndex !== -1) {\n return \\`Invalid numeric value provided for item #\\${invalidIndex + 1} - all provided items must be a valid number\\`;\n } `\n : \"\"\n }\n\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n ${camelCase(argument.name)} = value.split(\",\").map(value => value.trim()).filter(Boolean)${\n argument.kind === ReflectionKind.number\n ? `.map(Number)`\n : \"\"\n } ;\n `}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n {code`outro(\"Completed providing all required input parameters\");\n\n writeLine(\"\"); `}\n <hbr />\n <hbr />\n </ElseIfClause>\n </CommandHandlerDeclaration>\n </EntryFile>\n <For each={Object.values(command.children)}>\n {child => (\n <Show\n when={child.isVirtual}\n fallback={<CommandEntry command={child} />}>\n <VirtualCommandEntry command={child} />\n </Show>\n )}\n </For>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmDA,SAAgBwB,aAAaC,OAA0B;CACrD,MAAM,EAAEC,SAASC,SAASC,gBAAgB,GAAGC,SAASJ;CAEtD,MAAMK,UAAUrB,eAAiC;CACjD,MAAMsB,WAAW9B,eACfe,UACEU,QAAQM,SACLC,QAAOC,YAAW,CAACvB,qBAAqBuB,QA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D,SAASrB,KAAK,CAAA;;eAAe,IAAAK,WAAA;AAAA,uBACxDrD,IAAI;;oEAGGqE,SAASP,SAAStD,eAAewD,SAC7B,aACA,GAAE,mBACYK,SAASrB,KAAI,YAC/BqB,SAASI,cACL,KAAKtD,eAAekD,SAASI,YAAY,CAACC,QAAQ,QAAQ,GAAG,CAAA,KAC7D,GAAE;;;;;;;;;;;kCAaJL,SAASP,SAAStD,eAAewD,SAC7B;;;0CAIA,GAAE;;;;;;;;;8BAUV9C,UAAUmD,SAASrB,KAAK,CAAA,gEACxBqB,SAASP,SAAStD,eAAewD,SAC7B,iBACA,GAAE;;;eAET,CAAA;;aAAA,CAAA,CAAA;;WAAA,CAAA,CAAA;UAKZ,CAAA;SAEFhE,IAAI;;;SAEWsD,gBAAA,OAAA,EAAA,CAAA;SAAAA,gBAAA,OAAA,EAAA,CAAA;SAAA;;OAAA,CAAA,CAAA;;KAAA,CAAA;IAAA;;EAAA,CAAA,CAAA,EAAAT,gBAMrB3C,KAAG;EAAA,IAACoE,OAAI;AAAA,UAAEd,OAAOC,OAAO/B,QAAQ2B,SAAS;;EAAAA,WACvCuB,UAAK/B,gBACHzC,MAAI;GAAA,IACHoE,OAAI;AAAA,WAAEI,MAAMC;;GAAS,IACrBC,WAAQ;AAAA,WAAAjC,gBAAGrB,cAAY,EAACE,SAASkD,OAAK,CAAA;;GAAA,IAAAvB,WAAA;AAAA,WAAAR,gBACrCtB,qBAAmB,EAACG,SAASkD,OAAK,CAAA;;GAAA,CAAA;EAEtC,CAAA,CAAA"}
@@ -0,0 +1,85 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
3
+ let __alloy_js_core = require("@alloy-js/core");
4
+ let __alloy_js_typescript = require("@alloy-js/typescript");
5
+ let __shell_shock_preset_script_components_command_router = require("@shell-shock/preset-script/components/command-router");
6
+
7
+ //#region src/components/command-router.tsx
8
+ function CommandRouterSelectOptions(props) {
9
+ const { commands } = props;
10
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.For, {
11
+ get each() {
12
+ return Object.values(commands ?? {});
13
+ },
14
+ joiner: ",",
15
+ hardline: true,
16
+ children: (command) => command.isVirtual ? (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterSelectOptions, { get commands() {
17
+ return command.children ?? {};
18
+ } }) : __alloy_js_core.code`{ value: [${command.segments.map((segment) => `"${segment}"`).join(", ")}], label: "${command.icon ? `${command.icon} ` : ""}${command.title}", hint: "${command.description}" }`
19
+ });
20
+ }
21
+ /**
22
+ * A component that renders a command router interface, allowing users to select and execute commands from a provided list of commands and segments. This component serves as a wrapper around the base CommandRouter, adding additional UI elements and logic for command selection.
23
+ */
24
+ function CommandRouter(props) {
25
+ const { segments, commands } = props;
26
+ return [
27
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__shell_shock_preset_script_components_command_router.CommandRouter, (0, __alloy_js_core_jsx_runtime.mergeProps)(props, {
28
+ segments,
29
+ commands
30
+ })),
31
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
32
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
33
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
34
+ condition: __alloy_js_core.code`isInteractive && !isHelp`,
35
+ get children() {
36
+ return [
37
+ __alloy_js_core.code`
38
+ banner();
39
+
40
+ intro("Command selection");
41
+
42
+ let segments = await select({
43
+ message: "Please select a command to execute:",
44
+ options: [ `,
45
+ (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterSelectOptions, { commands }),
46
+ (0, __alloy_js_core_jsx_runtime.memo)(() => ` ],
47
+ });
48
+ if (isCancel(segments)) {
49
+ return;
50
+ }
51
+
52
+ let dynamics = {} as Record<string, string>;
53
+ for (const dynamic of segments.filter(segment => segment.startsWith("[") && segment.endsWith("]"))) {
54
+ const value = await text({
55
+ message: \`Please provide a value for \${dynamic.replace(/^\[+/, "").replace(/\]+$/, "")}:\`,
56
+ });
57
+ if (isCancel(value)) {
58
+ return;
59
+ }
60
+ dynamics[dynamic] = value;
61
+ }
62
+
63
+ segments = segments.map(segment => dynamics[segment] || segment);
64
+ const context = useApp();
65
+ context.set("args", [args.length > 0 ? args[0] : undefined, args.length > 1 ? args[1] : undefined, ...segments, ...args.slice(${segments.length + 2})].filter(Boolean) as string[]);
66
+
67
+ outro(\`Executing \${segments.join(" ")} command\`);
68
+
69
+ command = segments[0];
70
+ args = context.get("args"); `),
71
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__shell_shock_preset_script_components_command_router.CommandRouterBody, (0, __alloy_js_core_jsx_runtime.mergeProps)(props, {
72
+ segments,
73
+ commands
74
+ }))
75
+ ];
76
+ }
77
+ }),
78
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
79
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {})
80
+ ];
81
+ }
82
+
83
+ //#endregion
84
+ exports.CommandRouter = CommandRouter;
85
+ exports.CommandRouterSelectOptions = CommandRouterSelectOptions;