Forward installer parameters as named arguments
This commit is contained in:
parent
a2f27209b5
commit
e1de6b78c6
7 changed files with 53 additions and 29 deletions
|
@ -3,7 +3,9 @@ begin
|
||||||
set -l dir (status dirname)
|
set -l dir (status dirname)
|
||||||
source "$dir/../../lib/software.fish"
|
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 flags
|
||||||
set -l bins codium code
|
set -l bins codium code
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,8 @@ begin
|
||||||
sudo -HE pwsh "$dir/Main.ps1" Configure
|
sudo -HE pwsh "$dir/Main.ps1" Configure
|
||||||
end
|
end
|
||||||
|
|
||||||
function userConfig -V dir -a user
|
function userConfig -V dir
|
||||||
runPSUserConfig "$dir/Main.ps1" $user
|
runPSUserConfig "$dir/Main.ps1" $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
runInstaller $argv
|
runInstaller $argv
|
||||||
|
|
|
@ -7,8 +7,9 @@ begin
|
||||||
sudo systemctl enable --now docker
|
sudo systemctl enable --now docker
|
||||||
end
|
end
|
||||||
|
|
||||||
function userConfig -a name
|
function userConfig
|
||||||
sudo usermod -aG docker "$name"
|
argparse -i "user=" -- $argv
|
||||||
|
sudo usermod -aG docker "$_flag_user"
|
||||||
end
|
end
|
||||||
|
|
||||||
runInstaller $argv
|
runInstaller $argv
|
||||||
|
|
|
@ -8,8 +8,9 @@ begin
|
||||||
pwsh "$base" Configure
|
pwsh "$base" Configure
|
||||||
end
|
end
|
||||||
|
|
||||||
function userConfig -S -V base -a name
|
function userConfig -S -V base
|
||||||
runPSUserConfig "$base" $name
|
argparse -i "user=" -- $argv
|
||||||
|
runPSUserConfig "$base" $_flag_user
|
||||||
end
|
end
|
||||||
|
|
||||||
runInstaller $argv
|
runInstaller $argv
|
||||||
|
|
|
@ -7,8 +7,10 @@ begin
|
||||||
sudo cp "$dir/rclone.service" "$dir/rclone.target" "$dir/rclone@.service" /etc/systemd/user
|
sudo cp "$dir/rclone.service" "$dir/rclone.target" "$dir/rclone@.service" /etc/systemd/user
|
||||||
end
|
end
|
||||||
|
|
||||||
function userConfig -V dir -a name
|
function userConfig -V dir
|
||||||
source "$dir/../../../lib/settings.fish"
|
source "$dir/../../../lib/settings.fish"
|
||||||
|
argparse -i "user=" -- $argv
|
||||||
|
set -l name $_flag_user
|
||||||
set -l key "programs.rclone.configurations"
|
set -l key "programs.rclone.configurations"
|
||||||
set -l configs (getUserConfig "$name" "$key" --apply "builtins.attrNames" --json)
|
set -l configs (getUserConfig "$name" "$key" --apply "builtins.attrNames" --json)
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,9 @@ begin
|
||||||
or true
|
or true
|
||||||
end
|
end
|
||||||
|
|
||||||
function userConfig -a name
|
function userConfig
|
||||||
sudo usermod -aG libvirt "$name"
|
argparse -i "user=" -- $argv
|
||||||
|
sudo usermod -aG libvirt "$_flag_user"
|
||||||
end
|
end
|
||||||
|
|
||||||
runInstaller $argv
|
runInstaller $argv
|
||||||
|
|
|
@ -14,12 +14,18 @@ begin
|
||||||
functions -e "$actions[$i]"
|
functions -e "$actions[$i]"
|
||||||
end
|
end
|
||||||
|
|
||||||
function runPSUserAction -a script action name
|
function runPSUserAction
|
||||||
pwsh -CommandWithArgs '& $args[0] $args[1] @{ name=$args[2]; }' "$script" "$action" "$name"
|
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
|
end
|
||||||
|
|
||||||
function runPSUserConfig -a script name
|
function runPSUserConfig
|
||||||
runPSUserAction "$script" ConfigureUser "$name"
|
runPSUserAction $argv --action ConfigureUser
|
||||||
end
|
end
|
||||||
|
|
||||||
function inherit -V actions -a script -d "Inherits the installer from the specified script."
|
function inherit -V actions -a script -d "Inherits the installer from the specified script."
|
||||||
|
@ -29,6 +35,7 @@ begin
|
||||||
set -l baseName $functionName"Base"
|
set -l baseName $functionName"Base"
|
||||||
|
|
||||||
function $baseName -V script -V action
|
function $baseName -V script -V action
|
||||||
|
argparse -i "action=" -- $argv
|
||||||
fish "$script" $action $argv
|
fish "$script" $action $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,17 +46,22 @@ begin
|
||||||
end
|
end
|
||||||
|
|
||||||
function runInstaller -V dir -a action
|
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')
|
argparse -i "name=" -- $argv
|
||||||
set -l name (basename (dirname $path))
|
|
||||||
runInstallerAction $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
|
end
|
||||||
|
|
||||||
function runInstallerAction -V dir -V actions
|
function runInstallerAction -V dir -V actions
|
||||||
argparse "force" -- $argv
|
argparse -i "force" "name=" "action=" -- $argv
|
||||||
set -l install
|
set -l install
|
||||||
set -l args $_flag_force
|
set -l name $_flag_name
|
||||||
set -l name $argv[1]
|
set -l action $_flag_action
|
||||||
set -l action $argv[2]
|
set -l args $_flag_force --name "$name"
|
||||||
source "$dir/settings.fish"
|
source "$dir/settings.fish"
|
||||||
|
|
||||||
if [ -n "$_flag_force" ]
|
if [ -n "$_flag_force" ]
|
||||||
|
@ -65,14 +77,18 @@ begin
|
||||||
end
|
end
|
||||||
|
|
||||||
if [ -z "$action" ]
|
if [ -z "$action" ]
|
||||||
set action install
|
if [ -n "$argv[1]" ]
|
||||||
|
set action $argv[1]
|
||||||
|
set argv $argv[2..]
|
||||||
|
else
|
||||||
|
set action install
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i in (seq 1 2 (count $actions))
|
for i in (seq 1 2 (count $actions))
|
||||||
if [ "$action" = "$actions[$i]" ]
|
if [ "$action" = "$actions[$i]" ]
|
||||||
set -l message
|
set -l message
|
||||||
set -l function $actions[(math $i + 1)]
|
set -l function $actions[(math $i + 1)]
|
||||||
set -l argv $argv[3..]
|
|
||||||
set -l postRun "__postRun"
|
set -l postRun "__postRun"
|
||||||
functions -e $postRun
|
functions -e $postRun
|
||||||
|
|
||||||
|
@ -80,21 +96,22 @@ begin
|
||||||
case install
|
case install
|
||||||
set message "Installing `$name`..."
|
set message "Installing `$name`..."
|
||||||
|
|
||||||
function $postRun -V args -V name
|
function $postRun -V args
|
||||||
runInstallerAction $args $name configure
|
runInstallerAction $args --action configure
|
||||||
|
|
||||||
if not isConfigured || [ "$USER" != (getConfig "valhalla.setupUser.name") ]
|
if not isConfigured || [ "$USER" != (getConfig "valhalla.setupUser.name") ]
|
||||||
runInstallerAction $args $name userConfig
|
runInstallerAction $args --action userConfig
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
case configure
|
case configure
|
||||||
set message "Configuring `$name`..."
|
set message "Configuring `$name`..."
|
||||||
case userConfig
|
case userConfig
|
||||||
set -l user $argv[1]
|
argparse -i "user=" -- $argv
|
||||||
set argv $argv[2..]
|
set -l user "$_flag_user"
|
||||||
|
|
||||||
if [ -z "$user" ]
|
if [ -z "$user" ]
|
||||||
set user "$USER"
|
set user "$USER"
|
||||||
|
set -a args --user "$user"
|
||||||
end
|
end
|
||||||
|
|
||||||
if isProgramEnabled "$name" "$user" || $force
|
if isProgramEnabled "$name" "$user" || $force
|
||||||
|
@ -111,7 +128,7 @@ begin
|
||||||
echo $message
|
echo $message
|
||||||
end
|
end
|
||||||
|
|
||||||
"$function" $argv
|
"$function" $args $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
if functions -q $postRun
|
if functions -q $postRun
|
||||||
|
|
Loading…
Reference in a new issue