_topgrade() {
    local i cur prev opts cmd
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    cmd=""
    opts=""

    for i in ${COMP_WORDS[@]}
    do
        case "${cmd},${i}" in
            ",$1")
                cmd="topgrade"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        topgrade)
            opts="-t -c -n -v -k -y -h -V --edit-config --config-reference --tmux --cleanup --dry-run --no-retry --disable --only --custom-commands --env --verbose --keep --skip-notify --yes --disable-predefined-git-repos --config --remote-host-limit --show-skipped --log-filter --gen-completion --gen-manpage --no-self-update --help --version"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --disable)
                    COMPREPLY=($(compgen -W "am app_man asdf atom audit bin bob brew_cask brew_formula bun bun_packages cargo chezmoi chocolatey choosenim composer conda config_update containers custom_commands deb_get deno distrobox dkp_pacman dotnet emacs firmware flatpak flutter fossil gcloud gem ghcup github_cli_extensions git_repos gnome_shell_extensions go guix haxelib helm home_manager jetpack julia juliaup kakoune helix krew lure macports mamba miktex mas maza micro myrepos nix node opam pacdef pacstall pearl pip3 pip_review pip_review_local pipupgrade pipx pkg pkgin pnpm powershell protonup raco rcm remotes restarts rtcl ruby_gems rustup scoop sdkman self_update sheldon shell snap sparkle spicetify stack stew system tldr tlmgr tmux toolbx vagrant vcpkg vim vscode winget wsl wsl_update yadm yarn" -- "${cur}"))
                    return 0
                    ;;
                --only)
                    COMPREPLY=($(compgen -W "am app_man asdf atom audit bin bob brew_cask brew_formula bun bun_packages cargo chezmoi chocolatey choosenim composer conda config_update containers custom_commands deb_get deno distrobox dkp_pacman dotnet emacs firmware flatpak flutter fossil gcloud gem ghcup github_cli_extensions git_repos gnome_shell_extensions go guix haxelib helm home_manager jetpack julia juliaup kakoune helix krew lure macports mamba miktex mas maza micro myrepos nix node opam pacdef pacstall pearl pip3 pip_review pip_review_local pipupgrade pipx pkg pkgin pnpm powershell protonup raco rcm remotes restarts rtcl ruby_gems rustup scoop sdkman self_update sheldon shell snap sparkle spicetify stack stew system tldr tlmgr tmux toolbx vagrant vcpkg vim vscode winget wsl wsl_update yadm yarn" -- "${cur}"))
                    return 0
                    ;;
                --custom-commands)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --env)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --yes)
                    COMPREPLY=($(compgen -W "am app_man asdf atom audit bin bob brew_cask brew_formula bun bun_packages cargo chezmoi chocolatey choosenim composer conda config_update containers custom_commands deb_get deno distrobox dkp_pacman dotnet emacs firmware flatpak flutter fossil gcloud gem ghcup github_cli_extensions git_repos gnome_shell_extensions go guix haxelib helm home_manager jetpack julia juliaup kakoune helix krew lure macports mamba miktex mas maza micro myrepos nix node opam pacdef pacstall pearl pip3 pip_review pip_review_local pipupgrade pipx pkg pkgin pnpm powershell protonup raco rcm remotes restarts rtcl ruby_gems rustup scoop sdkman self_update sheldon shell snap sparkle spicetify stack stew system tldr tlmgr tmux toolbx vagrant vcpkg vim vscode winget wsl wsl_update yadm yarn" -- "${cur}"))
                    return 0
                    ;;
                -y)
                    COMPREPLY=($(compgen -W "am app_man asdf atom audit bin bob brew_cask brew_formula bun bun_packages cargo chezmoi chocolatey choosenim composer conda config_update containers custom_commands deb_get deno distrobox dkp_pacman dotnet emacs firmware flatpak flutter fossil gcloud gem ghcup github_cli_extensions git_repos gnome_shell_extensions go guix haxelib helm home_manager jetpack julia juliaup kakoune helix krew lure macports mamba miktex mas maza micro myrepos nix node opam pacdef pacstall pearl pip3 pip_review pip_review_local pipupgrade pipx pkg pkgin pnpm powershell protonup raco rcm remotes restarts rtcl ruby_gems rustup scoop sdkman self_update sheldon shell snap sparkle spicetify stack stew system tldr tlmgr tmux toolbx vagrant vcpkg vim vscode winget wsl wsl_update yadm yarn" -- "${cur}"))
                    return 0
                    ;;
                --config)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --remote-host-limit)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --log-filter)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --gen-completion)
                    COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
    esac
}

complete -F _topgrade -o nosort -o bashdefault -o default topgrade
