From 38ad846aeb01bc0f03624b304c82ed6a3e600fe5 Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Wed, 30 Sep 2015 08:37:53 -0300 Subject: [PATCH] Introduces kickstart.suppress_error function --- docs/kickstart/suppress_error.md | 15 +++++++++++++++ kickstart/recipes/kickstart.sh | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100644 docs/kickstart/suppress_error.md diff --git a/docs/kickstart/suppress_error.md b/docs/kickstart/suppress_error.md new file mode 100644 index 0000000..92e333e --- /dev/null +++ b/docs/kickstart/suppress_error.md @@ -0,0 +1,15 @@ +# kickstart.suppress_error command to run +Run the command with stder outputing to /dev/null. +Inform it is about to run. + +When debug flag is enable, does not redirect stderr to help debugging. +Returns the command result. + +### Example + +```bash +$ kickstart.suppress_error dpkg -s pkg-that-does-not-exist | grep 'Status:' +Running "dpkg -s pkg-that-does-not-exist" +``` + +If there was an error executing `dpkg`, it will not show up on the console unless the debugg flag is enabled. diff --git a/kickstart/recipes/kickstart.sh b/kickstart/recipes/kickstart.sh index 1350e9d..786f102 100644 --- a/kickstart/recipes/kickstart.sh +++ b/kickstart/recipes/kickstart.sh @@ -22,6 +22,16 @@ kickstart.mute() { return $? } +kickstart.suppress_error() { + kickstart.info "Running \"$*\"" + if kickstart.debugging; then + "$@" + else + "$@" 2>/dev/null + fi + return $? +} + kickstart.command_exists() { kickstart.mute which "$1" }