Skip to content

Commit 0d398a9

Browse files
committed
fix(cli): restore original options array
1 parent 00304bc commit 0d398a9

File tree

2 files changed

+85
-81
lines changed

2 files changed

+85
-81
lines changed

@commitlint/cli/src/cli.ts

+84-80
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import load from '@commitlint/load';
33
import lint from '@commitlint/lint';
44
import read from '@commitlint/read';
5-
import merge from 'lodash/merge';
65
import isFunction from 'lodash/isFunction';
76
import stdin from 'get-stdin';
87
import resolveFrom from 'resolve-from';
@@ -21,81 +20,83 @@ import {
2120
const pkg = require('../package');
2221

2322
const cli = yargs
24-
.option('color', {
25-
alias: 'c',
26-
default: true,
27-
describe: 'toggle colored output',
28-
type: 'boolean'
29-
})
30-
.option('config', {
31-
alias: 'g',
32-
describe: 'path to the config file',
33-
type: 'string'
34-
})
35-
.option('cwd', {
36-
alias: 'd',
37-
default: process.cwd(),
38-
describe: 'directory to execute in',
39-
type: 'string'
40-
})
41-
.option('edit', {
42-
alias: 'e',
43-
// default: false,
44-
describe:
45-
'read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG',
46-
type: 'string'
47-
})
48-
.option('env', {
49-
alias: 'E',
50-
describe:
51-
'check message in the file at path given by environment variable value',
52-
type: 'string'
53-
})
54-
.option('extends', {
55-
alias: 'x',
56-
describe: 'array of shareable configurations to extend',
57-
type: 'array'
58-
})
59-
.option('help-url', {
60-
alias: 'H',
61-
type: 'string',
62-
describe: 'helpurl in error message'
63-
})
64-
.option('from', {
65-
alias: 'f',
66-
describe: 'lower end of the commit range to lint; applies if edit=false',
67-
type: 'string'
68-
})
69-
.option('format', {
70-
alias: 'o',
71-
describe: 'output format of the results',
72-
type: 'string'
73-
})
74-
.option('parser-preset', {
75-
alias: 'p',
76-
describe: 'configuration preset to use for conventional-commits-parser',
77-
type: 'string'
78-
})
79-
.option('quiet', {
80-
alias: 'q',
81-
default: false,
82-
describe: 'toggle console output',
83-
type: 'boolean'
84-
})
85-
.option('to', {
86-
alias: 't',
87-
describe: 'upper end of the commit range to lint; applies if edit=false',
88-
type: 'string'
89-
})
90-
.option('version', {
91-
alias: 'v',
92-
type: 'boolean',
93-
describe: 'display version information'
94-
})
95-
.option('verbose', {
96-
alias: 'V',
97-
type: 'boolean',
98-
describe: 'enable verbose output for reports without problems'
23+
.options({
24+
color: {
25+
alias: 'c',
26+
default: true,
27+
description: 'toggle colored output',
28+
type: 'boolean'
29+
},
30+
config: {
31+
alias: 'g',
32+
description: 'path to the config file',
33+
type: 'string'
34+
},
35+
cwd: {
36+
alias: 'd',
37+
default: process.cwd(),
38+
description: 'directory to execute in',
39+
type: 'string'
40+
},
41+
edit: {
42+
alias: 'e',
43+
default: false,
44+
description:
45+
'read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG',
46+
type: 'string'
47+
},
48+
env: {
49+
alias: 'E',
50+
description:
51+
'check message in the file at path given by environment variable value',
52+
type: 'string'
53+
},
54+
extends: {
55+
alias: 'x',
56+
description: 'array of shareable configurations to extend',
57+
type: 'array'
58+
},
59+
'help-url': {
60+
alias: 'H',
61+
type: 'string',
62+
description: 'helpurl in error message'
63+
},
64+
from: {
65+
alias: 'f',
66+
description: 'lower end of the commit range to lint; applies if edit=false',
67+
type: 'string'
68+
},
69+
format: {
70+
alias: 'o',
71+
description: 'output format of the results',
72+
type: 'string'
73+
},
74+
'parser-preset': {
75+
alias: 'p',
76+
description: 'configuration preset to use for conventional-commits-parser',
77+
type: 'string'
78+
},
79+
quiet: {
80+
alias: 'q',
81+
default: false,
82+
description: 'toggle console output',
83+
type: 'boolean'
84+
},
85+
to: {
86+
alias: 't',
87+
description: 'upper end of the commit range to lint; applies if edit=false',
88+
type: 'string'
89+
},
90+
version: {
91+
alias: 'v',
92+
type: 'boolean',
93+
description: 'display version information'
94+
},
95+
verbose: {
96+
alias: 'V',
97+
type: 'boolean',
98+
description: 'enable verbose output for reports without problems'
99+
}
99100
})
100101
.help(
101102
'help',
@@ -242,7 +243,7 @@ async function main(options: CliFlags) {
242243
}
243244
}
244245

245-
function checkFromStdin(input: string[], flags: CliFlags) {
246+
function checkFromStdin(input: string[], flags: CliFlags): boolean {
246247
return input.length === 0 && !checkFromRepository(flags);
247248
}
248249

@@ -254,13 +255,16 @@ function checkFromEdit(flags: CliFlags) {
254255
return Boolean(flags.edit) || flags.env;
255256
}
256257

257-
function checkFromHistory(flags: CliFlags) {
258+
function checkFromHistory(flags: CliFlags): boolean {
258259
return typeof flags.from === 'string' || typeof flags.to === 'string';
259260
}
260261

261-
function normalizeFlags(flags: CliFlags) {
262+
function normalizeFlags(flags: CliFlags): CliFlags {
262263
const edit = getEditValue(flags);
263-
return merge({}, flags, {edit, e: edit});
264+
return {
265+
...flags,
266+
edit
267+
};
264268
}
265269

266270
function getEditValue(flags: CliFlags) {

@commitlint/cli/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export interface CliFlags {
22
color: boolean;
33
config?: string;
44
cwd: string;
5-
edit?: string;
5+
edit?: string | boolean;
66
env?: string;
77
extends?: (string | number)[];
88
help?: boolean;

0 commit comments

Comments
 (0)