Skip to content

Commit d16dbe4

Browse files
committed
feat(cli): implement new last CLI flag
1 parent 665d57a commit d16dbe4

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

@commitlint/cli/src/cli.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ test('should print help', async () => {
527527
edit=false [string]
528528
--git-log-args additional git log arguments as space separated string,
529529
example '--first-parent --cherry-pick' [string]
530+
-l, --last just analyze the last commit; applies if edit=false
531+
[boolean]
530532
-o, --format output format of the results [string]
531533
-p, --parser-preset configuration preset to use for
532534
conventional-commits-parser [string]

@commitlint/cli/src/cli.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ const cli = yargs
8282
"additional git log arguments as space separated string, example '--first-parent --cherry-pick'",
8383
type: 'string',
8484
},
85+
last: {
86+
alias: 'l',
87+
description: 'just analyze the last commit; applies if edit=false',
88+
type: 'boolean',
89+
},
8590
format: {
8691
alias: 'o',
8792
description: 'output format of the results',
@@ -212,7 +217,7 @@ async function main(args: MainArgs): Promise<void> {
212217

213218
if (messages.length === 0 && !checkFromRepository(flags)) {
214219
const err = new CliError(
215-
'[input] is required: supply via stdin, or --env or --edit or --from and --to',
220+
'[input] is required: supply via stdin, or --env or --edit or --last or --from and --to',
216221
pkg.name
217222
);
218223
yargs.showHelp('log');
@@ -355,7 +360,11 @@ function checkFromEdit(flags: CliFlags): boolean {
355360
}
356361

357362
function checkFromHistory(flags: CliFlags): boolean {
358-
return typeof flags.from === 'string' || typeof flags.to === 'string';
363+
return (
364+
typeof flags.from === 'string' ||
365+
typeof flags.to === 'string' ||
366+
typeof flags.last === 'boolean'
367+
);
359368
}
360369

361370
function normalizeFlags(flags: CliFlags): CliFlags {

@commitlint/cli/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface CliFlags {
99
'help-url'?: string;
1010
from?: string;
1111
'git-log-args'?: string;
12+
last?: boolean;
1213
format?: string;
1314
'parser-preset'?: string;
1415
quiet: boolean;

0 commit comments

Comments
 (0)