@@ -6,65 +6,50 @@ export {
6
6
parse
7
7
} ;
8
8
9
+ const reShortMessage = / ^ - ( [ a - z A - Z ] * ) m ( .* ) $ / ;
10
+ const reLongMessage = / ^ - - m e s s a g e ( = .* ) ? $ / ;
11
+
9
12
/**
10
- * Takes args, parses with minimist and some ugly vudoo, returns output
11
- *
12
- * TODO: Aww shit this is ugly. Rewrite with mega leet tests plz, kthnx.
13
+ * Strip message declaration from git arguments
13
14
*/
14
15
function parse ( rawGitArgs ) {
16
+ let result = [ ] ;
17
+ let skipNext = false ;
18
+
19
+ for ( const arg of rawGitArgs ) {
20
+ let match ;
15
21
16
- var args = minimist ( rawGitArgs , {
17
- alias : {
18
- m : 'message'
22
+ if ( skipNext ) {
23
+ skipNext = false ;
24
+ continue ;
19
25
}
20
- } ) ;
21
26
22
- // Loop through all keys
23
- var output = ' ' ;
27
+ match = reShortMessage . exec ( arg ) ;
28
+
29
+ if ( match ) {
30
+ if ( match [ 1 ] ) {
31
+ result . push ( `-${ match [ 1 ] } ` ) ;
32
+ }
24
33
25
- for ( let arg in args ) {
34
+ if ( ! match [ 2 ] ) {
35
+ skipNext = true ;
36
+ }
26
37
27
- if ( ! args . hasOwnProperty ( arg ) ) {
28
- // The current property is not a direct property
29
38
continue ;
30
39
}
40
+
41
+ match = reLongMessage . exec ( arg ) ;
42
+
43
+ if ( match ) {
44
+ if ( ! match [ 1 ] ) {
45
+ skipNext = true ;
46
+ }
31
47
32
- var key = arg ;
33
- var value = args [ arg ] ;
34
-
35
- /**
36
- * Ugly, but this is recompiles an argument string without
37
- * any messages passed in.
38
- */
39
- if ( key === '_' && value . length > 0 ) {
40
- // Anything in the _ array of strings is a one off file
41
- output += value . join ( ' ' ) + ' ' ;
42
- } else if ( key === 'verbose' ) {
43
- output += '--verbose ' ;
44
- } else if ( key === 'message' ) {
45
- /**
46
- * We strip out message because we're already handling this
47
- * in minimist's aliases.
48
- */
49
- continue ;
50
- } else if ( isString ( value ) ) {
51
- output += '-' + key + ' ' + value + ' ' ;
52
- } else if ( isArray ( value ) && value . length > 0 ) {
53
- output += '-' + key + ' ' + value . join ( ' -' + key ) + ' ' ;
54
- } else if ( value === true || value === false ) {
55
- output += '-' + key + ' ' ;
56
- } else {
57
- /**
58
- * Based on the current minimist object structure, we should
59
- * never get here, but we'll protect against breaking changes.
60
- */
61
48
continue ;
62
49
}
63
- }
64
50
65
- if ( output . trim ( ) . length < 1 ) {
66
- return '' ;
67
- } else {
68
- return output ;
51
+ result . push ( arg ) ;
69
52
}
53
+
54
+ return result ;
70
55
}
0 commit comments