diff --git a/@commitlint/cli/src/cli.test.ts b/@commitlint/cli/src/cli.test.ts index e5969f2e9d..0ab9c60560 100644 --- a/@commitlint/cli/src/cli.test.ts +++ b/@commitlint/cli/src/cli.test.ts @@ -428,6 +428,47 @@ test('should work with relative formatter path', async () => { expect(actual.exitCode).toBe(0); }); +test('should print help', async () => { + const cwd = await gitBootstrap('fixtures/default'); + const actual = await cli(['--help'], {cwd})(); + expect(actual.stdout).toMatchInlineSnapshot(` + "@commitlint/cli@8.3.5 - Lint your commit messages + + [input] reads from stdin if --edit, --env, --from and --to are omitted + + Options: + --color, -c toggle colored output [boolean] [default: true] + --config, -g path to the config file [string] + --cwd, -d directory to execute in + [string] [default: (Working Directory)] + --edit, -e read last commit message from the specified file or + fallbacks to ./.git/COMMIT_EDITMSG + [string] [default: false] + --env, -E check message in the file at path given by environment + variable value [string] + --extends, -x array of shareable configurations to extend [array] + --help-url, -H help url in error message [string] + --from, -f lower end of the commit range to lint; applies if + edit=false [string] + --format, -o output format of the results [string] + --parser-preset, -p configuration preset to use for + conventional-commits-parser [string] + --quiet, -q toggle console output [boolean] [default: false] + --to, -t upper end of the commit range to lint; applies if + edit=false [string] + --verbose, -V enable verbose output for reports without problems + [boolean] + -v, --version display version information [boolean] + -h, --help Show help [boolean]" + `); +}); + +test('should print version', async () => { + const cwd = await gitBootstrap('fixtures/default'); + const actual = await cli(['--version'], {cwd})(); + expect(actual.stdout).toMatch('@commitlint/cli@'); +}); + async function writePkg(payload: unknown, options: TestOptions) { const pkgPath = path.join(options.cwd, 'package.json'); const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8')); diff --git a/@commitlint/cli/src/cli.ts b/@commitlint/cli/src/cli.ts index 0aafc804de..6af2663f88 100644 --- a/@commitlint/cli/src/cli.ts +++ b/@commitlint/cli/src/cli.ts @@ -36,6 +36,7 @@ const cli = yargs cwd: { alias: 'd', default: process.cwd(), + defaultDescription: '(Working Directory)', description: 'directory to execute in', type: 'string' }, @@ -60,7 +61,7 @@ const cli = yargs 'help-url': { alias: 'H', type: 'string', - description: 'helpurl in error message' + description: 'help url in error message' }, from: { alias: 'f',