From ca614bb1cfdf4a21a7ddac5a8c74a0088f614b26 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 2 Nov 2024 18:14:54 +0100 Subject: [PATCH] Forward installer parameters as named arguments --- scripts/Arch/Software/vscode/main.fish | 4 +- scripts/Common/Software/aliae/main.fish | 4 +- scripts/Common/Software/docker/main.fish | 5 +- scripts/Common/Software/git/main.fish | 5 +- scripts/Common/Software/rclone/main.fish | 4 +- .../Common/Software/virt-manager/main.fish | 5 +- scripts/lib/software.fish | 55 ++++++++++++------- 7 files changed, 53 insertions(+), 29 deletions(-) diff --git a/scripts/Arch/Software/vscode/main.fish b/scripts/Arch/Software/vscode/main.fish index e075f409..b5bfd731 100755 --- a/scripts/Arch/Software/vscode/main.fish +++ b/scripts/Arch/Software/vscode/main.fish @@ -3,7 +3,9 @@ begin set -l dir (status dirname) source "$dir/../../lib/software.fish" - function setFlags -a user + function setFlags + argparse -i "user=" -- $argv + set -l user "$_flag_user" set -l flags set -l bins codium code diff --git a/scripts/Common/Software/aliae/main.fish b/scripts/Common/Software/aliae/main.fish index 35957f97..68363873 100755 --- a/scripts/Common/Software/aliae/main.fish +++ b/scripts/Common/Software/aliae/main.fish @@ -42,8 +42,8 @@ begin sudo -HE pwsh "$dir/Main.ps1" Configure end - function userConfig -V dir -a user - runPSUserConfig "$dir/Main.ps1" $user + function userConfig -V dir + runPSUserConfig "$dir/Main.ps1" $argv end runInstaller $argv diff --git a/scripts/Common/Software/docker/main.fish b/scripts/Common/Software/docker/main.fish index 9523507b..ed6b4fa6 100755 --- a/scripts/Common/Software/docker/main.fish +++ b/scripts/Common/Software/docker/main.fish @@ -7,8 +7,9 @@ begin sudo systemctl enable --now docker end - function userConfig -a name - sudo usermod -aG docker "$name" + function userConfig + argparse -i "user=" -- $argv + sudo usermod -aG docker "$_flag_user" end runInstaller $argv diff --git a/scripts/Common/Software/git/main.fish b/scripts/Common/Software/git/main.fish index fe0e473a..15a1d564 100755 --- a/scripts/Common/Software/git/main.fish +++ b/scripts/Common/Software/git/main.fish @@ -8,8 +8,9 @@ begin pwsh "$base" Configure end - function userConfig -S -V base -a name - runPSUserConfig "$base" $name + function userConfig -S -V base + argparse -i "user=" -- $argv + runPSUserConfig "$base" $_flag_user end runInstaller $argv diff --git a/scripts/Common/Software/rclone/main.fish b/scripts/Common/Software/rclone/main.fish index 68cee72f..cd45f24d 100755 --- a/scripts/Common/Software/rclone/main.fish +++ b/scripts/Common/Software/rclone/main.fish @@ -7,8 +7,10 @@ begin sudo cp "$dir/rclone.service" "$dir/rclone.target" "$dir/rclone@.service" /etc/systemd/user end - function userConfig -V dir -a name + function userConfig -V dir source "$dir/../../../lib/settings.fish" + argparse -i "user=" -- $argv + set -l name $_flag_user set -l key "programs.rclone.configurations" set -l configs (getUserConfig "$name" "$key" --apply "builtins.attrNames" --json) diff --git a/scripts/Common/Software/virt-manager/main.fish b/scripts/Common/Software/virt-manager/main.fish index 1fdadfc4..ebbb51db 100755 --- a/scripts/Common/Software/virt-manager/main.fish +++ b/scripts/Common/Software/virt-manager/main.fish @@ -12,8 +12,9 @@ begin or true end - function userConfig -a name - sudo usermod -aG libvirt "$name" + function userConfig + argparse -i "user=" -- $argv + sudo usermod -aG libvirt "$_flag_user" end runInstaller $argv diff --git a/scripts/lib/software.fish b/scripts/lib/software.fish index ca476b9f..f7c561b3 100755 --- a/scripts/lib/software.fish +++ b/scripts/lib/software.fish @@ -14,12 +14,18 @@ begin functions -e "$actions[$i]" end - function runPSUserAction -a script action name - pwsh -CommandWithArgs '& $args[0] $args[1] @{ name=$args[2]; }' "$script" "$action" "$name" + 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 -a script name - runPSUserAction "$script" ConfigureUser "$name" + function runPSUserConfig + runPSUserAction $argv --action ConfigureUser end function inherit -V actions -a script -d "Inherits the installer from the specified script." @@ -29,6 +35,7 @@ begin set -l baseName $functionName"Base" function $baseName -V script -V action + argparse -i "action=" -- $argv fish "$script" $action $argv end @@ -39,17 +46,22 @@ begin end function runInstaller -V dir -a action - set -l path (status stack-trace | head -n4 | tail -n1 | string replace --regex -- '^\s*called on line \d+ of file (.*)$' '$1') - set -l name (basename (dirname $path)) - runInstallerAction $name $argv + 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 "force" -- $argv + argparse -i "force" "name=" "action=" -- $argv set -l install - set -l args $_flag_force - set -l name $argv[1] - set -l action $argv[2] + 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" ] @@ -65,14 +77,18 @@ begin end if [ -z "$action" ] - set action install + 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 argv $argv[3..] set -l postRun "__postRun" functions -e $postRun @@ -80,21 +96,22 @@ begin case install set message "Installing `$name`..." - function $postRun -V args -V name - runInstallerAction $args $name configure + function $postRun -V args + runInstallerAction $args --action configure if not isConfigured || [ "$USER" != (getConfig "valhalla.setupUser.name") ] - runInstallerAction $args $name userConfig + runInstallerAction $args --action userConfig end end case configure set message "Configuring `$name`..." case userConfig - set -l user $argv[1] - set argv $argv[2..] + 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 @@ -111,7 +128,7 @@ begin echo $message end - "$function" $argv + "$function" $args $argv end if functions -q $postRun