Forward installer parameters as named arguments
This commit is contained in:
parent
f98fe148fc
commit
ca614bb1cf
7 changed files with 53 additions and 29 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
function runPSUserConfig -a script name
|
||||
runPSUserAction "$script" ConfigureUser "$name"
|
||||
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."
|
||||
|
@ -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
|
||||
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 -l name (basename (dirname $path))
|
||||
runInstallerAction $name $argv
|
||||
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" ]
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue