Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cli/src/android/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ const debug = Debug('capacitor:android:run');

export async function runAndroid(
config: Config,
{ target: selectedTarget, flavor: selectedFlavor, forwardPorts: selectedPorts }: RunCommandOptions,
{
target: selectedTarget,
targetName: selectedTargetName,
flavor: selectedFlavor,
forwardPorts: selectedPorts,
}: RunCommandOptions,
): Promise<void> {
const target = await promptForPlatformTarget(await getPlatformTargets('android'), selectedTarget);
const target = await promptForPlatformTarget(
await getPlatformTargets('android'),
selectedTarget ?? selectedTargetName,
selectedTargetName !== undefined,
);

const runFlavor = selectedFlavor || config.android?.flavor || '';

Expand Down
14 changes: 13 additions & 1 deletion cli/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export interface PlatformTarget {
export async function promptForPlatformTarget(
targets: PlatformTarget[],
selectedTarget?: string,
selectByName?: boolean,
): Promise<PlatformTarget> {
const { prompt } = await import('prompts');
const validTargets = targets.filter((t) => t.id !== undefined);
Expand Down Expand Up @@ -405,9 +406,20 @@ export async function promptForPlatformTarget(
}

const targetID = selectedTarget.trim();
const target = targets.find((t) => t.id === targetID);
const target = targets.find((t) => {
if (selectByName === true) {
return t.name === targetID;
}

t.id === targetID;
});

if (!target) {
if (selectByName) {
fatal(
`Invalid target name: ${c.input(targetID)}.\n` + `Valid targets are: ${targets.map((t) => t.name).join(', ')}`,
);
}
fatal(`Invalid target ID: ${c.input(targetID)}.\n` + `Valid targets are: ${targets.map((t) => t.id).join(', ')}`);
}

Expand Down
17 changes: 16 additions & 1 deletion cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export function runProgram(config: Config): void {
.option('--list', 'list targets, then quit')
.addOption(new Option('--json').hideHelp())
.option('--target <id>', 'use a specific target')
.option('--target-name <name>', 'use a specific target by name')
.option('--no-sync', `do not run ${c.input('sync')}`)
.option('--forwardPorts <port:port>', 'Automatically run "adb reverse" for better live-reloading support')
.option('-l, --live-reload', 'Enable Live Reload')
Expand All @@ -246,7 +247,20 @@ export function runProgram(config: Config): void {
config,
async (
platform,
{ scheme, flavor, list, json, target, sync, forwardPorts, liveReload, host, port, configuration },
{
scheme,
flavor,
list,
json,
target,
targetName,
sync,
forwardPorts,
liveReload,
host,
port,
configuration,
},
) => {
const { runCommand } = await import('./tasks/run');
await runCommand(config, platform, {
Expand All @@ -255,6 +269,7 @@ export function runProgram(config: Config): void {
list,
json,
target,
targetName,
sync,
forwardPorts,
liveReload,
Expand Down
13 changes: 11 additions & 2 deletions cli/src/ios/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ const debug = Debug('capacitor:ios:run');

export async function runIOS(
config: Config,
{ target: selectedTarget, scheme: selectedScheme, configuration: selectedConfiguration }: RunCommandOptions,
{
target: selectedTarget,
targetName: selectedTargetName,
scheme: selectedScheme,
configuration: selectedConfiguration,
}: RunCommandOptions,
): Promise<void> {
const target = await promptForPlatformTarget(await getPlatformTargets('ios'), selectedTarget);
const target = await promptForPlatformTarget(
await getPlatformTargets('ios'),
selectedTarget ?? selectedTargetName,
selectedTargetName !== undefined,
);

const runScheme = selectedScheme || config.ios.scheme;
const configuration = selectedConfiguration || 'Debug';
Expand Down
1 change: 1 addition & 0 deletions cli/src/tasks/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface RunCommandOptions {
list?: boolean;
json?: boolean;
target?: string;
targetName?: string;
sync?: boolean;
forwardPorts?: string;
liveReload?: boolean;
Expand Down
Loading