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