-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: list installed avd and connected devices (#66)
- Loading branch information
1 parent
1c5410e
commit 8234c7c
Showing
5 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import colors from 'ansi-colors'; | ||
|
||
import Logger from '../../../../logger'; | ||
import {Platform} from '../../interfaces'; | ||
import {getBinaryLocation} from '../../utils/common'; | ||
import {execBinarySync} from '../../utils/sdk'; | ||
import {showMissingBinaryHelp} from '../common'; | ||
|
||
export async function listInstalledAVDs(sdkRoot: string, platform: Platform): Promise<boolean> { | ||
try { | ||
const avdmanagerLocation = getBinaryLocation(sdkRoot, platform, 'avdmanager', true); | ||
if (!avdmanagerLocation) { | ||
showMissingBinaryHelp('avdmanager'); | ||
|
||
return false; | ||
} | ||
|
||
const installedAVDs = execBinarySync(avdmanagerLocation, 'avd', platform, 'list avd'); | ||
if (!installedAVDs) { | ||
Logger.log(`\n${colors.red('Failed to list installed AVDs!')} Please try again.`); | ||
|
||
return false; | ||
} | ||
|
||
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 occurred while listing installed AVDs.')); | ||
console.error(err); | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import colors from 'ansi-colors'; | ||
|
||
import Logger from '../../../../logger'; | ||
import {Platform} from '../../interfaces'; | ||
import ADB from '../../utils/appium-adb'; | ||
import {getBinaryLocation} from '../../utils/common'; | ||
import {showConnectedEmulators, showConnectedRealDevices, showMissingBinaryHelp} from '../common'; | ||
|
||
export async function listConnectedDevices(sdkRoot: string, platform: Platform): Promise<boolean> { | ||
const adbLocation = getBinaryLocation(sdkRoot, platform, 'adb', true); | ||
if (adbLocation === '') { | ||
showMissingBinaryHelp('adb'); | ||
|
||
return false; | ||
} | ||
|
||
const adb = await ADB.createADB({allowOfflineDevices: true}); | ||
const devices = await adb.getConnectedDevices(); | ||
|
||
if (!devices.length) { | ||
Logger.log(colors.yellow('No connected devices found.\n')); | ||
|
||
return true; | ||
} | ||
|
||
await showConnectedRealDevices(); | ||
await showConnectedEmulators(); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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'; | ||
|
||
export async function list(options: Options, sdkRoot: string, platform: Platform): Promise<boolean> { | ||
const optionsVerified = verifyOptions('list', options); | ||
if (!optionsVerified) { | ||
return false; | ||
} | ||
|
||
let subcommandFlag = optionsVerified.subcommandFlag; | ||
if (subcommandFlag === '') { | ||
subcommandFlag = await promptForFlag(); | ||
} | ||
|
||
if (subcommandFlag === 'avd') { | ||
return await listInstalledAVDs(sdkRoot, platform); | ||
} else if (subcommandFlag === 'device') { | ||
return await listConnectedDevices(sdkRoot, platform); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
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') { | ||
return 'device'; | ||
} | ||
|
||
return 'avd'; | ||
} |