#!/bin/env fish begin set -l dir (status dirname) set -l actions \ install installSW \ configure configureSW \ userConfig userConfig for i in (seq 2 2 (count $actions)) functions -e "$actions[$i]" end function runPSUserAction argparse -i "script=" "action=" "user=" -- $argv if [ -z "$_flag_script" ] set _flag_script $argv[1] end pwsh -CommandWithArgs '& $args[0] $args[1] @{ name=$args[2]; }' "$_flag_script" "$_flag_action" "$_flag_user" end function runPSUserConfig runPSUserAction $argv --action ConfigureUser end function inherit -V actions -a script -d "Inherits the installer from the specified script." for i in (seq 1 2 (count $actions)) set -l action $actions[$i] set -l functionName $actions[(math $i + 1)] set -l baseName $functionName"Base" function $baseName -V script -V action argparse -i "action=" -- $argv fish "$script" $action $argv end function $functionName -V baseName $baseName $argv end end end function runInstaller -V dir -a action argparse -i "name=" -- $argv if [ -z "$_flag_name" ] set -l path (status stack-trace | head -n4 | tail -n1 | string replace --regex -- '^\s*called on line \d+ of file (.*)$' '$1') set _flag_name (basename (dirname $path)) end runInstallerAction --name "$_flag_name" $argv end function runInstallerAction -V dir -V actions argparse -i "force" "name=" "action=" -- $argv set -l install set -l name $_flag_name set -l action $_flag_action set -l args $_flag_force --name "$name" source "$dir/settings.fish" if [ -n "$_flag_force" ] set force true else set force false end if isProgramEnabled $name || $force set install true else set install false end if [ -z "$action" ] if [ -n "$argv[1]" ] set action $argv[1] set argv $argv[2..] else set action install end end for i in (seq 1 2 (count $actions)) if [ "$action" = "$actions[$i]" ] set -l message set -l function $actions[(math $i + 1)] set -l postRun "__postRun" functions -e $postRun switch "$action" case install set message "Installing `$name`..." function $postRun -V args runInstallerAction $args --action configure if not isConfigured || [ "$USER" != (getConfig "valhalla.setupUser.name") ] runInstallerAction $args --action userConfig end end case configure set message "Configuring `$name`..." case userConfig argparse -i "user=" -- $argv set -l user "$_flag_user" if [ -z "$user" ] set user "$USER" set -a args --user "$user" end if isProgramEnabled "$name" "$user" || $force set install true else set install false end set message "Configuring `$name` for `$user`..." end if functions -q "$function" && $install if [ -n "$message" ] echo $message end "$function" $args $argv end if functions -q $postRun $postRun end end end end end