#compdef poetry

_poetry_365940863557df93_complete()
{
    local state com cur

    cur=${words[${#words[@]}]}

    # lookup for command
    for word in ${words[@]:1}; do
        if [[ $word != -* ]]; then
            com=$word
            break
        fi
    done

    if [[ ${cur} == --* ]]; then
        state="option"
        opts=("--ansi:Force ANSI output" "--help:Display this help message" "--no-ansi:Disable ANSI output" "--no-interaction:Do not ask any interactive question" "--quiet:Do not output any message" "--verbose:Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug" "--version:Display this application version")
    elif [[ $cur == $com ]]; then
        state="command"
        coms=("about:Short information about Poetry." "add:Add a new dependency to pyproject.toml." "build:Builds a package, as a tarball and a wheel by default." "cache\:clear:Clears poetry\'s cache." "check:Checks the validity of the pyproject.toml file." "config:Sets/Gets config options." "debug\:info:Shows debug information." "debug\:resolve:Debugs dependency resolution." "develop:Installs the current project in development mode. \(Deprecated\)" "help:Displays help for a command" "init:Creates a basic pyproject.toml file in the current directory." "install:Installs the project dependencies." "list:Lists commands" "lock:Locks the project dependencies." "new:Creates a new Python project at <path\>" "publish:Publishes a package to a remote repository." "remove:Removes a package from the project dependencies." "run:Runs a command in the appropriate environment." "script:Executes a script defined in pyproject.toml. \(Deprecated\)" "search:Searches for packages on remote repositories." "self\:update:Updates poetry to the latest version." "shell:Spawns a shell within the virtual environment." "show:Shows information about packages." "update:Update dependencies as according to the pyproject.toml file." "version:Bumps the version of the project.")
    fi

    case $state in
        (command)
            _describe 'command' coms
        ;;
        (option)
            case "$com" in

            (about)
            opts+=()
            ;;

            (add)
            opts+=("--allow-prereleases:Accept prereleases." "--dev:Add package as development dependency." "--dry-run:Outputs the operations but will not execute anything \(implicitly enables --verbose\)." "--extras:Extras to activate for the dependency." "--git:The url of the Git repository." "--optional:Add as an optional dependency." "--path:The path to a dependency." "--platform:Platforms for which the dependencies must be installed." "--python:Python version\( for which the dependencies must be installed.")
            ;;

            (build)
            opts+=("--format:Limit the format to either wheel or sdist.")
            ;;

            (cache:clear)
            opts+=("--all:Clear all caches.")
            ;;

            (check)
            opts+=()
            ;;

            (config)
            opts+=("--list:List configuration settings" "--unset:Unset configuration setting")
            ;;

            (debug:info)
            opts+=()
            ;;

            (debug:resolve)
            opts+=("--extras:Extras to activate for the dependency." "--install:Show what would be installed for the current system." "--python:Python version\(s\) to use for resolution." "--tree:Displays the dependency tree.")
            ;;

            (develop)
            opts+=()
            ;;

            (help)
            opts+=("--format:The output format \(txt, json, or md\)" "--raw:To output raw command help")
            ;;

            (init)
            opts+=("--author:Author name of the package" "--dependency:Package to require with an optional version constraint, e.g. requests:\^2.10.0 or requests=2.11.1" "--description:Description of the package" "--dev-dependency:Package to require for development with an optional version constraint, e.g. requests:\^2.10.0 or requests=2.11.1" "--license:License of the package" "--name:Name of the package")
            ;;

            (install)
            opts+=("--develop:Install given packages in development mode." "--dry-run:Outputs the operations but will not execute anything \(implicitly enables --verbose\)." "--extras:Extra sets of dependencies to install." "--no-dev:Do not install dev dependencies.")
            ;;

            (list)
            opts+=("--format:The output format \(txt, json, or md\)" "--raw:To output raw command list")
            ;;

            (lock)
            opts+=()
            ;;

            (new)
            opts+=("--name:Set the resulting package name." "--src:Use the src layout for the project.")
            ;;

            (publish)
            opts+=("--build:Build the package before publishing." "--password:The password to access the repository." "--repository:The repository to publish the package to." "--username:The username to access the repository.")
            ;;

            (remove)
            opts+=("--dev:Removes a package from the development dependencies." "--dry-run:Outputs the operations but will not execute anything \(implicitly enables --verbose\).")
            ;;

            (run)
            opts+=()
            ;;

            (script)
            opts+=()
            ;;

            (search)
            opts+=("--only-name:Search only in name.")
            ;;

            (self:update)
            opts+=("--preview:Install prereleases.")
            ;;

            (shell)
            opts+=()
            ;;

            (show)
            opts+=("--all:Show all packages \(even those not compatible with current system\)." "--latest:Show the latest version." "--no-dev:Do not list the dev dependencies." "--outdated:Show the latest version but only for packages that are outdated." "--tree:List the dependencies as a tree.")
            ;;

            (update)
            opts+=("--dry-run:Outputs the operations but will not execute anything \(implicitly enables --verbose\)." "--lock:Do not perform install \(only update the lockfile\)." "--no-dev:Do not install dev dependencies.")
            ;;

            (version)
            opts+=()
            ;;

            esac

            _describe 'option' opts
        ;;
        *)
            # fallback to file completion
            _arguments '*:file:_files'
    esac
}

_poetry_365940863557df93_complete "$@"
compdef _poetry_365940863557df93_complete /usr/bin/poetry
