@@ -3,18 +3,45 @@ const load = require('@commitlint/load')
3
3
const lint = require ( '@commitlint/lint' )
4
4
const format = require ( '@commitlint/format' )
5
5
6
- exports . command = 'commit'
6
+ const log = require ( '@dhis2/cli-helpers-engine' ) . reporter
7
7
8
- exports . describe = 'Format commit messages according to DHIS2 rules. '
8
+ exports . command = 'commit <cmd> [msg] '
9
9
10
- exports . builder = { }
10
+ exports . describe = 'Format commit messages according to standards.'
11
+
12
+ exports . builder = {
13
+ cmd : {
14
+ describe : 'check or apply style' ,
15
+ choices : [ 'check' , 'apply' ] ,
16
+ type : 'string' ,
17
+ } ,
18
+ msg : {
19
+ describe : 'arbitrary string to check' ,
20
+ type : 'string' ,
21
+ } ,
22
+ }
11
23
12
24
exports . handler = async function ( argv ) {
13
25
const config = require ( '@commitlint/config-conventional' )
26
+ const { cmd, msg } = argv
27
+
28
+ const check = cmd === 'check'
29
+ const apply = cmd === 'apply'
30
+
31
+ if ( check && ! msg ) {
32
+ log . error ( 'A commit msg is required when using check' )
33
+ process . exit ( 1 )
34
+ }
14
35
15
36
try {
16
37
const opts = await load ( config )
17
- const commit = await read ( { edit : true } )
38
+
39
+ let commit
40
+ if ( apply ) {
41
+ commit = await read ( { edit : true } )
42
+ } else {
43
+ commit = [ msg ]
44
+ }
18
45
19
46
const report = await lint (
20
47
commit [ 0 ] ,
@@ -39,7 +66,7 @@ exports.handler = async function(argv) {
39
66
process . exit ( 1 )
40
67
}
41
68
} catch ( err ) {
42
- process . stderr . write ( err )
69
+ log . error ( err )
43
70
process . exit ( 1 )
44
71
}
45
72
}
0 commit comments