When using Particle CLI, most commands send output to stdout, which is to be expected.
However, when a help command is used, its output is sent to stderr, which I find to be a confusing decision. Was this done to reduce output when using Particle CLI in scripts, or is this simply a overlooked bug that has persisted for many years?
I understand that most users probably do not notice this, nor care, but I’m curious to know why this is the current behavior.
Example using Python:
from subprocess import run, PIPE
# Run `particle list` and collect output
out = run(['particle', 'list'], stdout=PIPE, stderr=PIPE)
print(out.stdout) # The output of `particle list`
print(out.stderr) # Empty
# Run `particle` and collect output
out = run(['particle'], stdout=PIPE, stderr=PIPE)
print(out.stdout) # Empty
print(out.stderr) # The output of `particle`
# Run `particle help list` and collect output
out = run(['particle', 'help', 'list'], stdout=PIPE, stderr=PIPE)
print(out.stdout) # Empty
print(out.stderr) # The output of `particle help list`
Update:
I think I’ve answered my own question. Particle CLI uses yargs/yargs for command processing and displaying help messages, and the .showHelp()
method prints to console.error
when no arguments are provided.
I’ve opened a pull request to continue the discussion: