MCPcopy
hub / github.com/subquery/subql / makeCLIPrompt

Function makeCLIPrompt

packages/cli/src/adapters/utils.ts:337–387  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

335}
336
337export function makeCLIPrompt(): Prompt {
338 return async ({defaultValue, message, multiple, options, required, type}) => {
339 if (!options?.length && multiple) {
340 throw new Error('Multiple selection requires options to be provided');
341 }
342 if (type === 'string') {
343 if (options) {
344 if (multiple) {
345 return checkbox<string>({
346 message,
347 choices: (options as string[]).map((key) => ({value: key})),
348 });
349 }
350 return search<string>({
351 message,
352 source: filterInput<string>(options as string[]),
353 pageSize: 10,
354 });
355 }
356
357 return input({
358 message,
359 default: defaultValue as string | undefined,
360 required,
361 });
362 }
363 if (type === 'number') {
364 if (options) {
365 throw new Error('Number type does not support options');
366 }
367 const res = await input({
368 message,
369 default: defaultValue?.toString() as string | undefined,
370 required,
371 });
372 const num = Number(res);
373 if (isNaN(num)) {
374 throw new Error(`Input for ${message} must be a number`);
375 }
376 return num as any; // For some reason setting this to any fixes the type issue for this function
377 }
378 if (type === 'boolean') {
379 return confirm({
380 message,
381 default: defaultValue as boolean | undefined,
382 });
383 }
384
385 throw new Error(`Unsupported prompt type: ${type}`);
386 };
387}
388
389export function formatErrorCauses(e: Error): string {
390 let message = e.message;

Callers 12

runMethod · 0.90
runMethod · 0.90
runMethod · 0.90
runMethod · 0.90
runMethod · 0.90
runMethod · 0.90
runMethod · 0.90
runMethod · 0.90
runMethod · 0.90
runMethod · 0.90

Calls 2

filterInputFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected