From 911ed44e392e27247b8b2621e6d4bf9321575677 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 17 Apr 2019 16:46:15 +0200 Subject: [PATCH] Error management --- zsh/bin/update | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/zsh/bin/update b/zsh/bin/update index 275fa6d..7a56eb3 100755 --- a/zsh/bin/update +++ b/zsh/bin/update @@ -255,6 +255,32 @@ _print_help() { echo } +partial-test() { + case $1 in; + "system") return 0;; + "rust") return 0;; + "npm") return 0;; + "dotfiles") return 0;; + "neovim") return 0;; + "check") return 0;; + "startup") return 0;; + *) return 1;; + esac +} + +partial-update() { + case $1 in; + "system") update-system;; + "rust") update-rust;; + "npm") update-npm;; + "dotfiles") update-dotfiles;; + "neovim") update-neovim;; + "check") _check_date_if_format force;; + "startup") _check_date_if_format;; + *) return 1 + esac +} + main() { if [ $# -eq 0 ]; then @@ -292,22 +318,16 @@ main() { else - while [ $# -gt 0 ]; do - - case $1 in; - - "system") update-system;; - "rust") update-rust;; - "npm") update-npm;; - "dotfiles") update-dotfiles;; - "neovim") update-neovim;; - "check") _check_date_if_format force;; - "startup") _check_date_if_format;; - - esac - - shift + for part in $@; do + partial-test $part + if [ $? -ne 0 ]; then + echo "\033[1;31merror:\033[0m unrocognized update command \"$part\"" + return 1 + fi + done + for part in $@; do + partial-update $part done fi