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 2 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
13 changes: 12 additions & 1 deletion src/commands/android/subcommands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import colors from 'ansi-colors';
import * as dotenv from 'dotenv';
import path from 'path';

import {checkJavaInstallation, getSdkRootFromEnv} from '../utils/common';
import {checkJavaInstallation, getSdkRootFromEnv, getSubcommandHelp} from '../utils/common';
import {connect} from './connect';
import {getPlatformName} from '../../../utils';
import Logger from '../../../logger';
import {Options, Platform} from '../interfaces';
import {AVAILABLE_SUBCOMMANDS} from '../constants';

export class AndroidSubcommand {
sdkRoot: string;
Expand All @@ -26,6 +27,16 @@ 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`);

const help = getSubcommandHelp();
Logger.log(help);
Logger.log(`For complete Android help, run: ${colors.cyan('npx @nightwatch/mobile-helper android --help')}`);

return false;
}

this.loadEnvFromDotEnv();

const javaInstalled = checkJavaInstallation(this.rootDir);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/android/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ 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 += `Usage: ${colors.cyan('npx @nightwatch/mobile-helper android subcmd [subcmd-options]')}\n`;
garg3133 marked this conversation as resolved.
Show resolved Hide resolved
output += ' The following subcommands are used for different operations on Android SDK:\n\n';
output += `${colors.yellow('Subcommands and Subcommand-Options:')}\n`;

Expand Down
Loading