#!/bin/env fish
begin
    set -l dir (status dirname)

    function installSW
    end

    function configureSW
    end

    function userConfig -a user
    end

    function runInstaller -V dir -a action
        if [ -z "$action" ] || [ "$action" = "install" ]
            installSW $argv[2..]
        else if [ "$action" = "configure" ]
            configureSW $argv[2..]

            source "$dir/config.fish"
            set -l users (getUsers)

            if not isConfigured || [ "$USER" != (getConfig "valhalla.setupUser.name") ]
                runInstaller userConfig
            end

            for name in (echo "$users" | jq '.[]' --raw-output0 | string split0)
                if [ "$name" != "$USER" ]
                    runInstaller userConfig "$name"
                end
            end
        else if [ "$action" = "userConfig" ]
            set -l name $argv[2]

            if [ -z "$name" ]
                set name "$USER"
            end

            userConfig "$name" $argv[3..]
        end
    end
end