@magic/cli 0.0.44 → 0.0.46

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/README.md CHANGED
@@ -541,6 +541,17 @@ update dependencies
541
541
  - update dependencies
542
542
  - add colors to default arg output
543
543
 
544
- ##### 0.0.45 - unreleased
544
+ ##### 0.0.45
545
545
 
546
- ...
546
+ - help.example can be an array
547
+ - update dependencies
548
+ - cli.prompt - msg can be an array
549
+
550
+ ##### 0.0.46
551
+
552
+ - cli.exec allows stderrToStdout redirect config option
553
+ - update dependencies
554
+
555
+ ##### 0.0.47 - unreleased
556
+
557
+ - ...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic/cli",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "homepage": "https://magic.github.io/cli",
5
5
  "description": "declarative command line interfaces with aliasing, commands and environment sanitization",
6
6
  "scripts": {
@@ -40,13 +40,13 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@magic-modules/git-badges": "0.0.12",
43
- "@magic-modules/light-switch": "0.0.11",
44
- "@magic-modules/no-spy": "0.0.8",
45
- "@magic-modules/pre": "0.0.11",
46
- "@magic-themes/docs": "0.0.14",
47
- "@magic/core": "0.0.149",
48
- "@magic/format": "0.0.50",
49
- "@magic/test": "0.2.15"
43
+ "@magic-modules/light-switch": "0.0.12",
44
+ "@magic-modules/no-spy": "0.0.9",
45
+ "@magic-modules/pre": "0.0.12",
46
+ "@magic-themes/docs": "0.0.15",
47
+ "@magic/core": "0.0.153",
48
+ "@magic/format": "0.0.51",
49
+ "@magic/test": "0.2.17"
50
50
  },
51
51
  "author": "Wizards & Witches",
52
52
  "license": "AGPL-3.0",
package/src/exec.mjs CHANGED
@@ -6,7 +6,9 @@ const libName = '@magic/cli.exec'
6
6
 
7
7
  export const exec = (cmd, options = {}) =>
8
8
  new Promise((resolve, reject) => {
9
- child_process.exec(cmd, options, (err, stdout, stderr) => {
9
+ const { stderrToStdout, ...opts } = options
10
+
11
+ child_process.exec(cmd, opts, (err, stdout, stderr) => {
10
12
  if (err) {
11
13
  const e = error(err, 'E_EXEC_ERR')
12
14
  reject(e)
@@ -14,6 +16,11 @@ export const exec = (cmd, options = {}) =>
14
16
  }
15
17
 
16
18
  if (stderr) {
19
+ if (stderrToStdout) {
20
+ resolve(stderr)
21
+ return
22
+ }
23
+
17
24
  const e = error(new Error(`${libName}: ${cmd} error: ${stderr}`), 'E_EXEC_STDERR')
18
25
  reject(e)
19
26
  return
@@ -27,6 +27,18 @@ export const maybeHelp = args => {
27
27
  const name = help.name || '@magic/cli wrapped cli.'
28
28
  const header = is.string(help) ? help : help.text
29
29
 
30
+ const exampleArray = is.string(help.example) ? help.example.split('\n') : help.example
31
+
32
+ const exampleText = exampleArray
33
+ .map(a => {
34
+ if (a.trim().startsWith('#')) {
35
+ return log.color('green', a)
36
+ } else {
37
+ return a.trim()
38
+ }
39
+ })
40
+ .join('\n')
41
+
30
42
  const helpArray = [
31
43
  log.paint('green', name),
32
44
  '\n',
@@ -35,7 +47,7 @@ export const maybeHelp = args => {
35
47
  options.length && `${log.paint('grey', 'flags')}:\n${optionHelp}\n\n`,
36
48
  env.length && `${log.paint('grey', 'environment switches')}:\n${envHelp}\n\n`,
37
49
  'examples:\n',
38
- help.example,
50
+ exampleText,
39
51
  ]
40
52
 
41
53
  const errors = parsed.errors
package/src/prompt.mjs CHANGED
@@ -1,11 +1,13 @@
1
- import fs from 'fs'
1
+ import is from '@magic/types'
2
2
  import readline from 'readline'
3
3
 
4
- import log from '@magic/log'
5
-
6
4
  export const prompt = (msg = '', options = {}) =>
7
5
  new Promise((resolve, reject) => {
8
- const { yesNo = false, pass = false, std = process, yesDefault = false } = options
6
+ const { yesNo = false, std = process, yesDefault = false } = options
7
+
8
+ if (is.array(msg)) {
9
+ msg = msg.join(' ')
10
+ }
9
11
 
10
12
  if (yesNo) {
11
13
  let flag = 'y/N'