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

fixes #84, Add --help flag #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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