-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathoptions.js
More file actions
44 lines (37 loc) · 1.51 KB
/
options.js
File metadata and controls
44 lines (37 loc) · 1.51 KB
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
'use strict';
const { writeText, style } = require('../../utils/serverless-utils/log');
module.exports = (commandOptions) => {
const indentFillLength = 40;
for (const [option, optionsObject] of Object.entries(commandOptions)) {
let legacyOptionsIndentFill = '.'.repeat(Math.max(indentFillLength - option.length, 0));
let optionsIndentFill = ' '.repeat(Math.max(indentFillLength - option.length - 4, 0));
if (optionsObject.required) {
legacyOptionsIndentFill = legacyOptionsIndentFill.slice(
0,
legacyOptionsIndentFill.length - 18
);
optionsIndentFill = optionsIndentFill.slice(0, optionsIndentFill.length - 18);
} else {
legacyOptionsIndentFill = legacyOptionsIndentFill.slice(
0,
legacyOptionsIndentFill.length - 7
);
optionsIndentFill = optionsIndentFill.slice(0, optionsIndentFill.length - 7);
}
if (optionsObject.shortcut) {
legacyOptionsIndentFill = legacyOptionsIndentFill.slice(
0,
legacyOptionsIndentFill.length - 5
);
optionsIndentFill = optionsIndentFill.slice(0, optionsIndentFill.length - 5);
}
let shortcutInfo = '';
let requiredInfo = '';
if (optionsObject.shortcut) shortcutInfo = ` / -${optionsObject.shortcut}`;
if (optionsObject.required) requiredInfo = ' (required)';
const optionsUsage = optionsObject.usage
? optionsIndentFill + style.aside(optionsObject.usage)
: '';
writeText(`--${option}${shortcutInfo}${requiredInfo} ${optionsUsage}`);
}
};