Ver Fonte

Merge pull request #10 from vladimyr/depcheck

Implement dependency check helper
Siddharth Dushantha há 5 anos atrás
pai
commit
a6663cbb5f
1 ficheiros alterados com 8 adições e 4 exclusões
  1. 8 4
      tmpmail

+ 8 - 4
tmpmail

@@ -46,6 +46,10 @@ optional arguments:
 EOF
 }
 
+has(){
+    command -v "$1" >/dev/null 2>&1
+}
+
 
 generate_email_address(){
     # There are 2 ways which this function is called in this script.
@@ -235,10 +239,10 @@ main(){
     # Iterate of the array of dependencies and check if the user has them installed
     dependencies=(jq w3m curl awk)
     for dependency in "${dependencies[@]}"; do
-        type -p "$dependency" &>/dev/null || {
-        echo "error: Could not find '${dependency}', is it installed?" >&2
-        exit 1
-        }
+        if ! has "$dependency"; then
+            echo "error: Could not find '${dependency}', is it installed?" >&2
+            exit 1
+        fi
     done
 
     # Create the $TMPMAIL_DIR directory and dont throw any errors