From 1c983b81ea1947331b0045c8effc4b9a690e0144 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 24 Oct 2024 18:20:13 +0200 Subject: [PATCH] Implement hook enforcement using `argparse` --- scripts/Common/OS/setup.fish | 4 ++-- scripts/Common/Scripts/hooks.fish | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/Common/OS/setup.fish b/scripts/Common/OS/setup.fish index 87be8e93..9fd88bf6 100755 --- a/scripts/Common/OS/setup.fish +++ b/scripts/Common/OS/setup.fish @@ -57,7 +57,7 @@ function runSetup end and echo "Installing dependencies..." - and runHook installValhallaDeps true 'Please set up a function `installValhallaDeps` for installing `fish`, `git`, `jq`, `nix`, `sudo` and `tmux`.' + and runHook --force installValhallaDeps 'Please set up a function `installValhallaDeps` for installing `fish`, `git`, `jq`, `nix`, `sudo` and `tmux`.' and echo "Cloning project..." and source "$dir/../../copy-repo.fish" "$mountDir$PROJECT_CLONE_ROOT" @@ -65,7 +65,7 @@ function runSetup and runHook setupOS and echo "Preparing auto-login..." - and runHook autologin true "Please set up a function `autologin` for setting up autologin for the `root` user" + and runHook --force autologin "Please set up a function `autologin` for setting up autologin for the `root` user" and begin set -l script (string escape (getCloneFile (getInstallerScript))) diff --git a/scripts/Common/Scripts/hooks.fish b/scripts/Common/Scripts/hooks.fish index 49378f79..92946764 100755 --- a/scripts/Common/Scripts/hooks.fish +++ b/scripts/Common/Scripts/hooks.fish @@ -1,8 +1,12 @@ -function runHook -S -a name force message +function runHook -S + argparse "force" -- $argv + set -l name $argv[1] + set -l message $argv[2] + if type -q "$name" "$name" or exit 1 - else if $force + else if [ -n "$_flag_force" ] if test -n "$message" echo "$message" end