Skip to content

Commit

Permalink
updated error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
itsspriyansh committed Aug 20, 2024
1 parent a989ce2 commit ba6399c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/commands/android/subcommands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {checkJavaInstallation, getSdkRootFromEnv} from '../utils/common';
import {showHelp} from './help';
import {connect} from './connect';
import {install} from './install';
import {uninstall} from './uninstall';

export class AndroidSubcommand {
sdkRoot: string;
Expand Down Expand Up @@ -49,9 +50,7 @@ export class AndroidSubcommand {
}
this.sdkRoot = sdkRootEnv;

this.executeSubcommand();

return false;
return await this.executeSubcommand();
}

loadEnvFromDotEnv(): void {
Expand All @@ -65,6 +64,8 @@ export class AndroidSubcommand {
return await connect(this.options, this.sdkRoot, this.platform);
} else if (this.subcommand === 'install') {
return await install(this.options, this.sdkRoot, this.platform);
} else if (this.subcommand === 'uninstall') {
return await uninstall(this.options, this.sdkRoot, this.platform);
}

return false;
Expand Down
10 changes: 8 additions & 2 deletions src/commands/android/subcommands/uninstall/avd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export async function deleteAvd(sdkRoot: string, platform: Platform): Promise<bo

const installedAvds = execBinarySync(avdmanagerLocation, 'avdmanager', platform, 'list avd -c');
if (!installedAvds) {
Logger.log(`${colors.yellow('Failed to fetch installed AVDs.')} Please try again.`);
Logger.log(`${colors.yellow('Failed to fetch installed AVDs.')} Please try again.\n`);
Logger.log('Alternatively, to see the list of installed AVDs, run the following command:');
Logger.log(colors.cyan(' npx @nightwatch/mobile-helper android list --avd\n'));

return false;
}
Expand All @@ -37,11 +39,15 @@ export async function deleteAvd(sdkRoot: string, platform: Platform): Promise<bo
const deleteStatus = await execBinaryAsync(avdmanagerLocation, 'avdmanager', platform, `delete avd --name '${avdName}'`);

if (deleteStatus?.includes('deleted')) {
Logger.log(`${colors.green('AVD deleted successfully!')}`);
Logger.log(colors.green('AVD deleted successfully!\n'));

return true;
}

Logger.log(`${colors.red('Something went wrong while deleting AVD.')}`);
Logger.log(`Please run ${colors.cyan('npx @nightwatch/mobile-helper android list -avd')} to check if the AVD was deleted.`);
Logger.log('If the AVD is still present, please try deleting the AVD again.\n');

return false;
} catch (error) {
Logger.log(colors.red('Error occured while deleting AVD.'));
Expand Down
11 changes: 11 additions & 0 deletions src/commands/android/subcommands/uninstall/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Options, Platform} from '../../interfaces';
import {deleteAvd} from './avd';

export async function uninstall(options: Options, sdkRoot: string, platform: Platform): Promise<boolean> {
if (options.avd) {
return await deleteAvd(sdkRoot, platform);
}

return false;
}

0 comments on commit ba6399c

Please sign in to comment.