@toptal/davinci-cli-shared 1.5.2-alpha-fx-2815-trailing-comma--eslint.127 → 1.5.2-alpha-fx-2755-codebase-specific-workflows.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-cli-shared",
3
- "version": "1.5.2-alpha-fx-2815-trailing-comma--eslint.127+ab9fe716",
3
+ "version": "1.5.2-alpha-fx-2755-codebase-specific-workflows.131+b2bc74b6",
4
4
  "description": "Shared CLI code and CLI engine for davinci",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,5 +20,5 @@
20
20
  "js-yaml": "^4.1.0",
21
21
  "vorpal": "^1.12.0"
22
22
  },
23
- "gitHead": "ab9fe71658d458c63ac71de4b1ce828507b8487e"
23
+ "gitHead": "b2bc74b6947156d1489a42f820be1832f53b870d"
24
24
  }
@@ -7,7 +7,8 @@ const commandsLoader = (commandCreators, vorpalInstance) => {
7
7
  description,
8
8
  options = [],
9
9
  allowUnknownOptions = false,
10
- action
10
+ action,
11
+ help
11
12
  } = commandCreator
12
13
 
13
14
  const commandInstance = vorpalInstance
@@ -18,6 +19,10 @@ const commandsLoader = (commandCreators, vorpalInstance) => {
18
19
 
19
20
  options.forEach(option => commandInstance.option(option.name, option.label))
20
21
 
22
+ if (help) {
23
+ commandInstance.help(help)
24
+ }
25
+
21
26
  if (allowUnknownOptions) {
22
27
  commandInstance.allowUnknownOptions()
23
28
  }
@@ -26,9 +26,42 @@ const grey = (...args) => {
26
26
  console.log(chalk.grey(...prettifyObjectIfExist(args)))
27
27
  }
28
28
 
29
+ const generatePadding = (str, width, delimiter = ' ') => {
30
+ const len = Math.max(0, Math.floor(width) - str.trim().length)
31
+
32
+ return str + Array(len + 1).join(delimiter)
33
+ }
34
+
35
+ /**
36
+ * Build a list of commands
37
+ * @param commands Array<[name, description]>
38
+ */
39
+ const prettifyCommands = commands => {
40
+ if (!commands.length) {
41
+ return ''
42
+ }
43
+
44
+ const width = commands.reduce(
45
+ (max, commandX) => Math.max(max, commandX[0].length),
46
+ 0
47
+ )
48
+
49
+ return commands
50
+ .map(([command, description]) => {
51
+ const prefix =
52
+ ' ' + chalk.green(generatePadding(command, width)) + ' '
53
+ const suffix = generatePadding('', width + 6) + description
54
+
55
+ return prefix + suffix
56
+ })
57
+ .join('\n')
58
+ }
59
+
29
60
  module.exports = {
30
61
  green,
31
62
  yellow,
32
63
  red,
33
- grey
64
+ grey,
65
+ generatePadding,
66
+ prettifyCommands
34
67
  }