-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflagger.js
More file actions
26 lines (26 loc) · 775 Bytes
/
flagger.js
File metadata and controls
26 lines (26 loc) · 775 Bytes
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
function flags(obj) {
var res = { alias: { h: 'help' } };
if (obj.length === 0) return res;
let help = obj.help;
delete obj.help;
for (let key in obj) {
res.alias[key[0]] = key;
}
if (help) {
res.description = help.map((key) => {
let desc = obj[key];
return `-${key[0]}, --${key}: ${desc}`;
});
} else {
res.description = Object.keys(obj).map((key) => {
let desc = obj[key];
return `-${key[0]}, --${key}: ${desc}`;
});
}
res.description.length === 0
? (res.description = '')
: res.description.length === 1
? (res.description = res.description[0])
: (res.description = res.description.join('\n'));
return res;
}