@@ -15,6 +15,7 @@ import {
15
15
ParserPreset ,
16
16
QualifiedConfig
17
17
} from '@commitlint/types' ;
18
+ import { CliError } from './cli-error' ;
18
19
19
20
const pkg = require ( '../package' ) ;
20
21
@@ -106,9 +107,9 @@ const cli = yargs
106
107
. usage ( `${ pkg . name } @${ pkg . version } - ${ pkg . description } \n` )
107
108
. usage (
108
109
`[input] reads from stdin if --edit, --env, --from and --to are omitted`
109
- ) . argv ;
110
+ ) ;
110
111
111
- main ( cli ) . catch ( err => {
112
+ main ( cli . argv ) . catch ( err => {
112
113
setTimeout ( ( ) => {
113
114
if ( err . type === pkg . name ) {
114
115
process . exit ( 1 ) ;
@@ -137,12 +138,11 @@ async function main(options: CliFlags) {
137
138
. filter ( Boolean ) ;
138
139
139
140
if ( messages . length === 0 && ! checkFromRepository ( flags ) ) {
140
- // TODO: create custom error??
141
- const err = new Error (
142
- '[input] is required: supply via stdin, or --env or --edit or --from and --to'
141
+ const err = new CliError (
142
+ '[input] is required: supply via stdin, or --env or --edit or --from and --to' ,
143
+ pkg . name
143
144
) ;
144
- ( err as any ) . type = pkg . name ; // TODO
145
- console . log ( `${ cli . help } \n` ) ;
145
+ yargs . showHelp ( 'log' ) ;
146
146
console . log ( err . message ) ;
147
147
throw err ;
148
148
}
@@ -241,10 +241,7 @@ async function main(options: CliFlags) {
241
241
}
242
242
243
243
if ( ! report . valid ) {
244
- // TODO: create custom error??
245
- const err = new Error ( output ) ;
246
- ( err as any ) . type = pkg . name ;
247
- throw err ;
244
+ throw new CliError ( output , pkg . name ) ;
248
245
}
249
246
}
250
247
0 commit comments