Skip to content

Commit

Permalink
fixes #84, Add --help flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dineshmanideep committed Dec 20, 2024
1 parent 6799fc2 commit 9ea0ca1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
31 changes: 30 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,33 @@ export const NIGHTWATCH_TITLE = `
|___/
`;

export const AVAILABLE_CONFIG_FLAGS = ['yes', 'generate-config', 'browser', 'y', 'b', 'mobile', 'app', 'native'];
export const AVAILABLE_CONFIG_FLAGS = ['yes', 'generate-config', 'browser', 'y', 'b', 'mobile', 'app', 'native'];

export const HELPTEXT = `
Nightwatch - Integrated Testing Framework for Modern Web and Mobile Applications
Usage:
npm init nightwatch@latest -- [options]
Options:
--generate-config Generate a configuration file in an existing Nightwatch project.
--mobile Set up testing for mobile browsers only.
-b, --browser <name> Specify browser(s) for testing (e.g., chrome, firefox).
-y, --yes Skip prompts and use default configuration.
-h, --help Show this help message and exit.
Examples:
Initialize a new project in the current directory:
npm init nightwatch@latest
Initialize a new project in a specified directory:
npm init nightwatch@latest ./path/to/project
Set up mobile testing only:
npm init nightwatch@latest -- --mobile
Generate a configuration file in an existing project:
npm init nightwatch@latest -- --generate-config
For more information, visit: https://nightwatchjs.org
`;
14 changes: 11 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {execSync} from 'child_process';
import colors from 'ansi-colors';
import {prompt} from 'inquirer';
import {NightwatchInitiator} from '@nightwatch/setup-tools';
import {NIGHTWATCH_TITLE, AVAILABLE_CONFIG_FLAGS} from './constants';
import {NIGHTWATCH_TITLE, AVAILABLE_CONFIG_FLAGS , HELPTEXT} from './constants';
import Logger from './logger';
import minimist from 'minimist';
import suggestSimilarOption from './utils/suggestSimilar';
Expand All @@ -17,11 +17,12 @@ export const run = async () => {
try {
const argv = process.argv.slice(2);
const {_: args, ...options} = minimist(argv, {
boolean: ['generate-config', 'native'],
boolean: ['generate-config', 'native' , 'help'],
alias: {
yes: 'y',
browser: 'b',
native: 'app'
native: 'app',
help: 'h'
}
});

Expand All @@ -30,6 +31,13 @@ export const run = async () => {
options.browser = [options.browser];
}

// Display help if --help or -h is passed
if (options.help) {
Logger.info(NIGHTWATCH_TITLE);
Logger.info(HELPTEXT);
return;
}

// Filter flags that are not present in AVAILABLE_CONFIG_ARGS
const wrongUserFlags = Object.keys(options).filter((word) => !AVAILABLE_CONFIG_FLAGS.includes(word));

Expand Down

0 comments on commit 9ea0ca1

Please sign in to comment.