# shellcheck shell=dash

___x_cmd log init user

xrc:mod:lib     user        add ls current passwd group

___x_cmd_user___main(){
    [ "$#" -gt 0 ]  ||  set -- name

    local op="$1";      shift
    case "$op" in
        add|ls|rm|name|isroot|id|in)
                        ___x_cmd_user_"$op"     "$@" ;;
        p|passwd)       ___x_cmd_user_passwd    "$@" ;;
        g|group)        ___x_cmd_user_group     "$@" ;;
        -h|--help)      ___x_cmd help -m user   "$@" ;;
    esac
}

# TODO: in --one-of
___x_cmd_user_in(){
    local a; a=" $(___x_cmd_cmds id -Gn) " || {
        user:error "fail to judge current user is sudo user" --user "$USER" --cmd "id -Gn"
        return 2
    }

    [ $# -gt 0 ]    ||  M="expect more than 1 argument" N=user log:ret:64

    while [ $# -gt 0 ]; do
        # work only in linux. in macos, the sudo group name is admin. This can also be redefined.
        case " $a " in
            *" $1 "*)     shift; continue      ;;
            *)            return 1      ;;
        esac
    done
}
