shelljs / shx

Portable Shell Commands for Node
MIT License
1.72k stars 44 forks source link

--silent doesn't work #208

Open its-dibo opened 1 year ago

its-dibo commented 1 year ago

the following example is from readme.md

{
  "scripts": {
    "clean": "shx --silent rm -rf build dist && shx echo Done",
    "example": "shx --silent ls fakeFileName"
  }
}

output:

npm ERR! Lifecycle script `example` failed with error: 
npm ERR! Error: command failed
nfischer commented 1 year ago

I think --silent works as intended in your example. All this flag does is it tells shx to suppress error output, and that's what happened (shx did not print the error message).

The Lifecycle script error message is printed by npm because shx returned a non-zero status code. So if you want to suppress all the error output, I recommend you do as I advised in #210.

I think we could clarify this a bit better in the README documentation by adding a couple examples:

...
$ shx --silent ls fakeFileName  # silence error output

# Add this part:
$ shx --silent ls fakeFileName || shx true # silence error output and ignore the exit status

and also add

{
  "scripts": {
    "clean": "shx rm -rf build dist && shx echo Done",
    "copy-suppress-errors": "shx --silent cp some_file.txt destination/ && shx true"
  }
}
its-dibo commented 1 year ago

[docs] to be more clear:

--silent suppress the original error but exits with code 1, to ignore the error either use --ignore (if supported) or use shx invalid-cmd || true