diff --git a/src/commands/android/subcommands/index.ts b/src/commands/android/subcommands/index.ts index a2ff1ee..cdcc05d 100644 --- a/src/commands/android/subcommands/index.ts +++ b/src/commands/android/subcommands/index.ts @@ -4,10 +4,11 @@ import path from 'path'; import Logger from '../../../logger'; import {getPlatformName} from '../../../utils'; +import {AVAILABLE_SUBCOMMANDS} from '../constants'; import {Options, Platform} from '../interfaces'; -import {checkJavaInstallation, getSdkRootFromEnv} from '../utils/common'; -import {showHelp} from './help'; +import {checkJavaInstallation, getSdkRootFromEnv, getSubcommandHelp} from '../utils/common'; import {connect} from './connect'; +import {showHelp} from './help'; import {install} from './install'; export class AndroidSubcommand { @@ -28,11 +29,21 @@ export class AndroidSubcommand { } async run(): Promise { + if (!Object.keys(AVAILABLE_SUBCOMMANDS).includes(this.subcommand)) { + Logger.log(`${colors.red(`unknown subcommand passed: ${this.subcommand}`)}\n`); + Logger.log(getSubcommandHelp()); + Logger.log(`For individual subcommand help, run: ${colors.cyan('npx @nightwatch/mobile-helper android SUBCOMMAND --help')}`); + Logger.log(`For complete Android help, run: ${colors.cyan('npx @nightwatch/mobile-helper android --help')}\n`); + + return false; + } + if (this.options.help) { showHelp(this.subcommand); return true; } + this.loadEnvFromDotEnv(); const javaInstalled = checkJavaInstallation(this.rootDir); diff --git a/src/commands/android/utils/common.ts b/src/commands/android/utils/common.ts index ab7ea2a..0ae2b28 100644 --- a/src/commands/android/utils/common.ts +++ b/src/commands/android/utils/common.ts @@ -216,9 +216,9 @@ export const checkJavaInstallation = (cwd: string): boolean => { export const getSubcommandHelp = (): string => { let output = ''; - output += `Usage: ${colors.cyan('npx @nightwatch/mobile-helper android [subcmd] [subcmd-options]')}\n`; - output += ' The following subcommands are used for different operations on Android SDK:\n\n'; - output += `${colors.yellow('Subcommands and Subcommand-Options:')}\n`; + output += `Usage: ${colors.cyan('npx @nightwatch/mobile-helper android SUBCOMMAND [flag] [configs]')}\n`; + output += ' Perform common Android SDK operations using subcommands.\n\n'; + output += `${colors.yellow('Subcommands (with available flags and configs):')}\n`; Object.keys(AVAILABLE_SUBCOMMANDS).forEach(subcommand => { const subcmd = AVAILABLE_SUBCOMMANDS[subcommand];