Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show help for invalid subcommand #48

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 13 additions & 2 deletions src/commands/android/subcommands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,11 +29,21 @@ export class AndroidSubcommand {
}

async run(): Promise<boolean> {
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);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/android/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Loading