MCPcopy
hub / github.com/ionic-team/capacitor / promptForPlatform

Function promptForPlatform

cli/src/common.ts:335–367  ·  view source on GitHub ↗
(
  platforms: string[],
  promptMessage: string,
  selectedPlatformName?: string,
)

Source from the content-addressed store, hash-verified

333}
334
335export async function promptForPlatform(
336 platforms: string[],
337 promptMessage: string,
338 selectedPlatformName?: string,
339): Promise<string> {
340 const { prompt } = await import('prompts');
341
342 if (!selectedPlatformName) {
343 const answers = await prompt(
344 [
345 {
346 type: 'select',
347 name: 'mode',
348 message: promptMessage,
349 choices: platforms.map((p) => ({ title: p, value: p })),
350 },
351 ],
352 { onCancel: () => process.exit(1) },
353 );
354
355 return answers.mode.toLowerCase().trim();
356 }
357
358 const platformName = selectedPlatformName.toLowerCase().trim();
359
360 if (!(await isValidPlatform(platformName))) {
361 const knownPlatforms = await getKnownPlatforms();
362
363 fatal(`Invalid platform: ${c.input(platformName)}.\n` + `Valid platforms include: ${knownPlatforms.join(', ')}`);
364 }
365
366 return platformName;
367}
368
369export interface PlatformTarget {
370 id: string;

Callers 4

runCommandFunction · 0.90
addCommandFunction · 0.90
openCommandFunction · 0.90
buildCommandFunction · 0.90

Calls 3

fatalFunction · 0.90
isValidPlatformFunction · 0.85
getKnownPlatformsFunction · 0.85

Tested by

no test coverage detected