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 displaying command output. verbose should be just for the command #91
Comments
That is not displaying the output of the command |
Just to clarify:
Expected Output:
Then:
Expected Output:
|
this is not how I design the system. In non-verbose mode nothing is displayed and user decides what to show. Just console.log needed stuff. |
I see. Just wondering if you can change that to work like bash when |
We can discuss this. What’s your idea? |
How to disable all output in your case? |
I'd like to disable just printing out the command itself. I still would like to get the command output itself. One use case is redirection. Example:
Right now, we'll get the command itself listed in This is the suggested patch to be applied:
|
I think all output should not be disabled. However, if that is a requirement I'd add a new command:
|
Verbose is like debug. Turn on or off. If you need redirect maybe it’s better to be explicit and console.log only things you meed to? What if first command must be silenced and second redirected? |
I think "verbose" means additional information, not only command output. I agree "verbose" is like "debug". I'm thinking of as a regular CLI when all output is redirected. That's the reason I think
Output:
Then:
Output
|
I get this. But what not |
Main reason for not doing that is just for avoiding verbosity. If we have many commands in the same script, then the script will use much more lines. I'm thinking of |
You can combine them into one big call to $. |
I'm also looking for an option to turn off outputing the command that is being ran. The documentation stating that |
My idea is to use |
Again, what about just this? let p = await $`...`
console.log(p.toString()) Or via helper like this: function print(p) {
console.log(p.toString())
return p
}
print(await $`...`) This way we don't need to introduce another API, and this is good. |
@antonmedv commands that output stdout to show progress will only show their full output at the end of execution with the work around you are proposing, this is not desirable. With using verbose they output to stdout as they are running. |
@antonmedv I think your workaround is adding unneeded complexity. I'm still thinking of |
Consider next example: #/bin/bash
date # Printed.
FOO=$(pwd) # Captured. And same in zx: $.verbose = false
await $`date`
let foo = await $`pwd` In JS there is no way to tell what second command is captured and not needed to be printed. Only user can decide what should be redirected to stdout of zx script. Or we can think of something line redirection API. |
That's my point. In your Can we see if we it's possible to capture the second one without printing it out? |
I would be fine doing something like $.verbose = false
$.output = true
await $`date`
$.output = false
let foo = await $`pwd` personally. |
What about this: let p = $`yes`
p.stdout.pipe(process.stdout)
await p |
Your example doesn't appear to work.
|
I’m developing it) |
@adrianord Yeah, that is my idea (#91 (comment)) and my proposed path here :) |
Got something even more interesting: await $`npm init`.pipe(process.stdout) |
This code already in the master branch and can be tested! |
@antonmedv I guess my only gripe is what about commands that output to both stdout and stderr. Some programs print their warnings to stderr. Would it be possible to also have a |
@adrianord for this specific case you need to do something like this: $.verbose = false
await $`program 2>&1`.pipe(process.stdout) Or if you want to redirect in to stderr: $.verbose = false
let p = $`program`
p.stdout.pipe(process.stdout)
p.stderr.pipe(process.stderr)
await p |
With this new let {stdout} = await $`echo "hello"`
.pipe($`awk '{print $1" world"}'`)
.pipe($`tr '[a-z]' '[A-Z]'`)
assert(stdout === 'HELLO WORLD\n') |
Please forgive me this is off-topic, but this is the only place I can post this. I've been looking at proxy-www which I found on Modern Javascript: Everything you missed over the last 10 years (2020) via a post on hn wondering if it would be possible to simplify the syntax you demonstrated to something like this: let {stdout} = await $.pipes
.echo(`"hello"`)
.awk(`'{print $1" world"}'`)
.tr(`'[a-z]' '[A-Z]'`) or even something like this, maybe (using Korn shell if available): let {stdout} = await $.bin.korn
.echo(`-ne "hello\n"`) // -ne is just an example arg to show that everything is still pretty much the same.
.awk(`'{print $1" world"}'`)
.program(`2>&1`)
.bork(`2>/dev/null`)
.ls('-lh', '/usr') // <-- look here it is a raw arg array for node's child_process.spawn you grab it with ...arg
.tr(`'[a-z]' '[A-Z]'`) Again, apologies for the off-topic post. Your program is great, love the take on Knuth's Literate Programming where you allow |
I think the pipe method is okay and should work. |
@antonmedv I'm OK with the pipeline method! Thanks! |
For anyone arriving here, and wanting to log only the output of a command, not the commands themselves
The only way I could get piped commands to actually be captured, and then output it, was the following, which I'm sure could be done better, but was the only thing that worked for me - note I did try using the
option, but no luck for me, lol! This allows me to just copy some stuff I try at the command line straight in as well, so not too bad :D
|
EDIT: can ignore most of this, skip to next commentA different angle: personally I'm happy with the existing control of where command output goes. What I'm missing though is a globally controlled mode to log ALL commands, and just the commands. Exactly like
In particular, IMHO it's none of user's concern whether its output was captured and re-printed vs. directly sent to stdout/stderr.
Ahem OK so I guess there are uses for different combinations 🃏... Let's see which are easy/hard now:
The rest are "niceties" one could DIY, but for centralized "if debug" knob to become more useful, I think would be great to get:
EDIT: zx's |
Oh wait, All possible LogEntry types; here are examples of the 2 I cared about:
E.g. this was enough for me: $.log = ({ kind, cmd, verbose }) => {
// I want default quiet, so using my own env var instead of zx's `--quiet` flag.
// Also checking per-LogEntry `verbose` allows silencing particular command with `.quiet()`!
if (kind === 'cmd' && process.env.VERBOSE && verbose) {
console.error(`+ ${cmd}`);
}
}; Awesome. |
Works for me.
Originally posted by @antonmedv in #80 (comment)
The text was updated successfully, but these errors were encountered: