Skip to content

Commit

Permalink
Refactors.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Aug 22, 2024
1 parent cf796a1 commit 8c40b0c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/commands/android/subcommands/list/avd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ export async function listInstalledAVDs(sdkRoot: string, platform: Platform): Pr
return false;
}

Logger.log(installedAVDs);
if (installedAVDs.split('\n').length < 3) {
Logger.log(colors.red('No installed AVDs found!'));
} else {
Logger.log(installedAVDs);
}

return true;
} catch (err) {
Logger.log(colors.red('Error occured while listing installed AVDs.'));
Logger.log(colors.red('Error occurred while listing installed AVDs.'));
console.error(err);

return false;
}
}

1 change: 0 additions & 1 deletion src/commands/android/subcommands/list/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ export async function listConnectedDevices(sdkRoot: string, platform: Platform):

return true;
}

21 changes: 10 additions & 11 deletions src/commands/android/subcommands/list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,43 @@ import inquirer from 'inquirer';

import Logger from '../../../../logger';
import {Options, Platform} from '../../interfaces';
import {verifyOptions} from '../common';
import {listInstalledAVDs} from './avd';
import {listConnectedDevices} from './device';
import {verifyOptions} from '../common';

export async function list(options: Options, sdkRoot: string, platform: Platform): Promise<boolean> {
const optionsVerified = verifyOptions('list', options);
if (!optionsVerified) {
return false;
}

const subcommandFlag = optionsVerified.subcommandFlag;
let subcommandFlag = optionsVerified.subcommandFlag;
if (subcommandFlag === '') {
await flagsPrompt(options);
subcommandFlag = await promptForFlag();
}

if (options.avd) {
if (subcommandFlag === 'avd') {
return await listInstalledAVDs(sdkRoot, platform);
} else if (options.device) {
} else if (subcommandFlag === 'device') {
return await listConnectedDevices(sdkRoot, platform);
}

return false;
}

async function flagsPrompt(options: Options) {
async function promptForFlag(): Promise<string> {
const flagAnswer = await inquirer.prompt({
type: 'list',
name: 'flag',
message: 'Select what do you want to list:',
choices: ['Connected devices', 'Installed AVDs']
});
Logger.log();

const flag = flagAnswer.flag;
if (flag === 'Connected devices') {
options.device = true;
} else if (flag === 'Installed AVDs') {
options.avd = true;
return 'device';
}
Logger.log();
}

return 'avd';
}

0 comments on commit 8c40b0c

Please sign in to comment.