@@ -6,65 +6,50 @@ export {
66 parse
77} ;
88
9+ const reShortMessage = / ^ - ( [ a - z A - Z ] * ) m ( .* ) $ / ;
10+ const reLongMessage = / ^ - - m e s s a g e ( = .* ) ? $ / ;
11+
912/**
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
1314 */
1415function parse ( rawGitArgs ) {
16+ let result = [ ] ;
17+ let skipNext = false ;
18+
19+ for ( const arg of rawGitArgs ) {
20+ let match ;
1521
16- var args = minimist ( rawGitArgs , {
17- alias : {
18- m : 'message'
22+ if ( skipNext ) {
23+ skipNext = false ;
24+ continue ;
1925 }
20- } ) ;
2126
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+ }
2433
25- for ( let arg in args ) {
34+ if ( ! match [ 2 ] ) {
35+ skipNext = true ;
36+ }
2637
27- if ( ! args . hasOwnProperty ( arg ) ) {
28- // The current property is not a direct property
2938 continue ;
3039 }
40+
41+ match = reLongMessage . exec ( arg ) ;
42+
43+ if ( match ) {
44+ if ( ! match [ 1 ] ) {
45+ skipNext = true ;
46+ }
3147
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- */
6148 continue ;
6249 }
63- }
6450
65- if ( output . trim ( ) . length < 1 ) {
66- return '' ;
67- } else {
68- return output ;
51+ result . push ( arg ) ;
6952 }
53+
54+ return result ;
7055}
0 commit comments