Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$.verbose = false; is not working as expected when using zx as a module #80

Closed
bsnux opened this issue May 14, 2021 · 2 comments
Closed

Comments

@bsnux
Copy link

bsnux commented May 14, 2021

Expected Behavior

When $.verbose = false then only output of the command should be displayed.

Example:

#!/usr/local/bin/node
import { $ } from 'zx'
$.verbose = false
await ($`uptime`)

Expected output:

9:42  up 16 days, 21 mins, 1 user, load averages: 1.63 2.00 3.2

Actual Behavior

Based on the example above:

$ uptime
9:42  up 16 days, 21 mins, 1 user, load averages: 1.63 2.00 3.2

Steps to Reproduce the Problem

  1. Create a js file with the code mentioned above
  2. $ node index.js

Specifications

  • Version: zx version 1.2.2
  • Platform: Darwin 19.6.0 Darwin Kernel Version 19.6.0

Suggested patch:

--- index.mjs
+++ index.mjs.original
@@ -53,12 +53,12 @@
     let child = exec($.prefix + cmd, options)
     let stdout = '', stderr = '', combined = ''
     child.stdout.on('data', data => {
-      process.stdout.write(data)
+      if ($.verbose) process.stdout.write(data)
       stdout += data
       combined += data
     })
     child.stderr.on('data', data => {
-      process.stderr.write(data)
+      if ($.verbose) process.stderr.write(data)
       stderr += data
       combined += data
     })
@antonmedv
Copy link
Collaborator

antonmedv commented May 15, 2021

Works for me.

⌘ zx ⎇ main ❯❯❯ cat foo.mjs
#!/usr/local/bin/node
import { $ } from './index.mjs'
$.verbose = false
await ($`uptime`)
⌘ zx ⎇ main ❯❯❯ node foo.mjs
⌘ zx ⎇ main ❯❯❯

@bsnux
Copy link
Author

bsnux commented May 17, 2021

That example is not displaying the output of the command. verbose should be just for the command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants