Allow fetching program config with named args

This commit is contained in:
Manuel Thalmann 2024-11-02 22:45:22 +01:00
parent 608b7a9e51
commit e203f93c6b
2 changed files with 16 additions and 7 deletions

View file

@ -40,13 +40,21 @@ function getOSConfig -S -a property
getConfig "$(getOSConfigRoot).$property" $argv[2..] getConfig "$(getOSConfigRoot).$property" $argv[2..]
end end
function getProgramConfig -S -a name user function getProgramConfig -S
argparse -i "name=" "user=" -- $argv
set -l name $_flag_name
set -l user $_flag_user
set -l option "programs.$name" set -l option "programs.$name"
if [ -z "$name" ]
set name $argv[1]
set argv $argv[2..]
end
if [ -z "$user" ] if [ -z "$user" ]
getOSConfig "$option" $argv[3..] --fallback "{}" getOSConfig "$option" $argv --fallback "{}"
else else
getUserConfig "$user" "$option" $argv[3..] --fallback "{}" getUserConfig "$user" "$option" $argv --fallback "{}"
end end
end end
@ -78,8 +86,9 @@ function isEnabled -S -a property
getConfig "$property" --json | jq --exit-status >/dev/null getConfig "$property" --json | jq --exit-status >/dev/null
end end
function isProgramEnabled -S -a name user function isProgramEnabled -S
getProgramConfig "$name" "$user" --json 2>/dev/null | jq --exit-status ".enable" >/dev/null argparse -i "user=" "name=" -- $argv
getProgramConfig --user "$_flag_user" --name "$_flag_name" --json 2>/dev/null | jq --exit-status ".enable" >/dev/null
end end
function isOSEnabled -S -a property function isOSEnabled -S -a property

View file

@ -117,7 +117,7 @@ begin
set force false set force false
end end
if isProgramEnabled $name || $force if isProgramEnabled $args || $force
set install true set install true
else else
set install false set install false
@ -167,7 +167,7 @@ begin
set -a args --user "$user" set -a args --user "$user"
end end
if isProgramEnabled "$name" "$user" || $force if isProgramEnabled $args || $force
set install true set install true
else else
set install false set install false