#!/bin/bash
#
# THIS FILE IS GENERATED. DO NOT EDIT.
#
# Completion strategy (fastest-first):
#   1. Shortcuts    — single-character aliases resolved before any other logic.
#   2. Top-level    — all known subcommands when no subcommand has been typed yet.
#   3. Flags        — matched when the current token starts with '-'.
#   3.5. Option values  — static values for known flags (e.g. --to sqlite).
#   3.6. Comma values   — comma-separable list (e.g. cds add ai,hana).
#   4. File positionals — files/dirs for subcommands that take a path argument.
#   4.6. String positionals — fixed word list (e.g. cds help <tab>).
#   5. Dynamic fallback — calls 'cds completion' for anything not covered above.
#
# compopt -o nospace suppresses the trailing space bash normally appends after a
# completion, which is required for path completions (so the user can keep typing
# a subdirectory) and for flag names (so '=' can follow immediately).
CDS_COMMAND="cds"

_completeCds()
{
    local current previous cmd
    COMPREPLY=()
    current="${COMP_WORDS[COMP_CWORD]}"
    previous="${COMP_WORDS[COMP_CWORD - 1]}"
    # The subcommand is always the second token (index 1).
    cmd="${COMP_WORDS[1]}"
    # Step 1: resolve single-character shortcuts to their canonical command name
    # so that subsequent case statements only need to handle canonical names.
    case "$cmd" in
        i) cmd=init ;;
        a) cmd=add ;;
        y) cmd=bind ;;
        m) cmd=import ;;
        c) cmd=compile ;;
        p) cmd=parse ;;
        s) cmd=serve ;;
        w) cmd=watch ;;
        e) cmd=env ;;
        b) cmd=build ;;
        d) cmd=deploy ;;
        l) cmd=login ;;
        o) cmd=logout ;;
        t) cmd=test ;;
        v) cmd=version ;;
        h) cmd=help ;;
        r) cmd=repl ;;
    esac

    # Step 2: top-level — offer all known subcommands when no subcommand has been
    # typed yet (COMP_WORDS includes the command itself, so ≤ 2 means "cds <cursor>").
    if [[ "${#COMP_WORDS[@]}" -le 2 ]]; then
        COMPREPLY=( $(compgen -W ""add" "bind" "bindings" "build" "compile" "completion" "debug" "deploy" "env" "eval" "export" "gen" "help" "import" "init" "inspect" "lint" "login" "logout" "minify" "mock" "parse" "pull" "push" "repl" "run" "serve" "subscribe" "test" "unsubscribe" "up" "upgrade" "upgrade-tenant" "version" "watch"" -- "$current") )
        compopt -o nospace
        return 0
    fi

    # Step 3: flag/option completion — only triggered when the token starts with '-'.
    if [[ "$current" == -* ]]; then
        case "$cmd" in
            add) COMPREPLY=( $(compgen -W ""--base" "--cdm" "--cloudevents" "--composition-records" "--content-type" "--data:for" "--dry" "--filter" "--for" "--for-app" "--force" "--into" "--java:mvn" "--js" "--keys-only" "--out" "--package" "--plan" "--records" "--sap" "--shell" "--ts" "--unified-runtime" "--with-telemetry" "--workspace" "--y"" -- "$current") ) ;;
            bind) COMPREPLY=( $(compgen -W ""--credentials" "--exec" "--for" "--kind" "--no-create-service-key" "--on" "--out" "--output-file" "--to" "--to-app-services"" -- "$current") ) ;;
            bindings) COMPREPLY=( $(compgen -W ""--as"" -- "$current") ) ;;
            build) COMPREPLY=( $(compgen -W ""--dest" "--for" "--log-level" "--no-clean" "--no-ws-pack" "--options-model" "--opts" "--project" "--src" "--ws" "--ws-pack"" -- "$current") ) ;;
            compile) COMPREPLY=( $(compgen -W ""--all" "--asyncapi:merged" "--beta" "--clean" "--conceptual" "--dest" "--dialect" "--docs" "--files" "--flavor" "--for" "--from" "--lang" "--locations" "--log-level" "--min" "--odata-version" "--openapi:config-file" "--openapi:diagram" "--openapi:servers" "--openapi:url" "--parse" "--plain" "--resolved" "--service" "--sort" "--sources" "--sql-dialect" "--to"" -- "$current") ) ;;
            completion) COMPREPLY=( $(compgen -W ""--add" "--curr" "--line" "--prev" "--profile" "--remove" "--shell"" -- "$current") ) ;;
            debug) COMPREPLY=( $(compgen -W ""--cf" "--force" "--host" "--k8s" "--kyma" "--no-devtools" "--port"" -- "$current") ) ;;
            deploy) COMPREPLY=( $(compgen -W ""--auto-undeploy" "--delta-from" "--dry" "--for" "--model-only" "--no-build" "--no-save" "--on" "--out" "--resolve-bindings" "--script" "--store-credentials" "--to" "--tunnel-address" "--vcap-file" "--with-auto-schema-evolution" "--with-mocks" "--xdry"" -- "$current") ) ;;
            env) COMPREPLY=( $(compgen -W ""--for" "--json" "--keys" "--list" "--mocked" "--process-env" "--properties" "--raw" "--resolve-bindings" "--sources"" -- "$current") ) ;;
            eval) COMPREPLY=( $(compgen -W ""--quiet" "--silent"" -- "$current") ) ;;
            export) COMPREPLY=( $(compgen -W ""--artifact" "--as" "--cleanse" "--data" "--debug" "--dry" "--for" "--from" "--inspect" "--keep" "--mvn" "--plugin" "--reuse" "--services" "--skip" "--texts" "--to"" -- "$current") ) ;;
            import) COMPREPLY=( $(compgen -W ""--as" "--asyncapi" "--config" "--data-product" "--dependencies" "--destination" "--dry" "--edmx" "--for" "--force" "--from" "--group" "--include-namespaces" "--into-namespace" "--keep-namespace" "--name" "--no-copy" "--no-save" "--odata" "--odata-v2-annotations" "--openapi" "--out" "--resolve-bindings" "--rfc" "--services"" -- "$current") ) ;;
            init) COMPREPLY=( $(compgen -W ""--add" "--base" "--force" "--java" "--java:mvn" "--java:package" "--lint:custom" "--lint:custom:example" "--no-db" "--nodejs" "--verbose"" -- "$current") ) ;;
            inspect) COMPREPLY=( $(compgen -W ""--kind" "--list" "--stats"" -- "$current") ) ;;
            lint) COMPREPLY=( $(compgen -W ""--cache" "--cache-file" "--cache-location" "--cache-strategy" "--color" "--concurrency" "--config" "--debug" "--env-info" "--exit-on-fatal-error" "--ext" "--fix" "--fix-dry-run" "--fix-type" "--flag" "--format" "--global" "--help" "--ignore-pattern" "--init" "--inspect-config" "--max-warnings" "--mcp" "--no-color" "--no-config-lookup" "--no-error-on-unmatched-pattern" "--no-ignore" "--no-inline-config" "--no-warn-ignored" "--output-file" "--parser" "--parser-options" "--pass-on-no-patterns" "--pass-on-unpruned-suppressions" "--plugin" "--print-config" "--prune-suppressions" "--quiet" "--report-unused-disable-directives" "--report-unused-disable-directives-severity" "--report-unused-inline-configs" "--rule" "--stats" "--stdin" "--stdin-filename" "--suppress-all" "--suppress-rule" "--suppressions-location" "--version"" -- "$current") ) ;;
            login) COMPREPLY=( $(compgen -W ""--app-tid" "--client" "--mtls" "--no-browser" "--passcode" "--plain" "--port" "--save-refresh-token" "--subdomain" "--user"" -- "$current") ) ;;
            logout) COMPREPLY=( $(compgen -W ""--clear-invalid" "--delete-settings" "--subdomain" "--url"" -- "$current") ) ;;
            minify) COMPREPLY=( $(compgen -W ""--cleanse" "--debug" "--dry" "--inspect" "--keep" "--skip"" -- "$current") ) ;;
            mock) COMPREPLY=( $(compgen -W ""--at" "--from" "--in-memory" "--in-memory?" "--mocked" "--port" "--project" "--projects" "--resolve-bindings" "--service" "--to" "--watch" "--with" "--with-bindings" "--with-mocks" "--with-mtx" "--workers"" -- "$current") ) ;;
            parse) COMPREPLY=( $(compgen -W ""--all" "--asyncapi:merged" "--beta" "--clean" "--conceptual" "--dest" "--dialect" "--docs" "--files" "--flavor" "--for" "--from" "--lang" "--locations" "--log-level" "--min" "--odata-version" "--openapi:config-file" "--openapi:diagram" "--openapi:servers" "--openapi:url" "--parse" "--plain" "--resolved" "--service" "--sort" "--sources" "--sql-dialect" "--to"" -- "$current") ) ;;
            pull) COMPREPLY=( $(compgen -W ""--client" "--from" "--mtls" "--passcode" "--subdomain" "--user"" -- "$current") ) ;;
            push) COMPREPLY=( $(compgen -W ""--async" "--client" "--mtls" "--passcode" "--subdomain" "--sync" "--to" "--user"" -- "$current") ) ;;
            repl) COMPREPLY=( $(compgen -W ""--ql" "--run" "--use"" -- "$current") ) ;;
            run) COMPREPLY=( $(compgen -W ""--at" "--from" "--in-memory" "--in-memory?" "--mocked" "--port" "--project" "--projects" "--resolve-bindings" "--service" "--to" "--watch" "--with" "--with-bindings" "--with-mocks" "--with-mtx" "--workers"" -- "$current") ) ;;
            serve) COMPREPLY=( $(compgen -W ""--at" "--from" "--in-memory" "--in-memory?" "--mocked" "--port" "--project" "--projects" "--resolve-bindings" "--service" "--to" "--watch" "--with" "--with-bindings" "--with-mocks" "--with-mtx" "--workers"" -- "$current") ) ;;
            subscribe) COMPREPLY=( $(compgen -W ""--body" "--local" "--resolve-bindings" "--to" "--user"" -- "$current") ) ;;
            test) COMPREPLY=( $(compgen -W ""--exclude" "--failed" "--files" "--include" "--list" "--passed" "--quiet" "--recent" "--silent" "--timeout" "--unmute" "--verbose" "--workers"" -- "$current") ) ;;
            unsubscribe) COMPREPLY=( $(compgen -W ""--from" "--local" "--resolve-bindings" "--user"" -- "$current") ) ;;
            up) COMPREPLY=( $(compgen -W ""--namespace" "--overlay" "--to"" -- "$current") ) ;;
            upgrade) COMPREPLY=( $(compgen -W ""--at" "--fix" "--local" "--report" "--resolve-bindings" "--user"" -- "$current") ) ;;
            upgrade-tenant) COMPREPLY=( $(compgen -W ""--at" "--local" "--resolve-bindings" "--user"" -- "$current") ) ;;
            version) COMPREPLY=( $(compgen -W ""--abs" "--all" "--depth" "--info" "--json" "--markdown" "--omit"" -- "$current") ) ;;
            watch) COMPREPLY=( $(compgen -W ""--debug" "--exclude" "--experimental-hot-reload" "--ext" "--in-memory" "--in-memory?" "--include" "--inspect" "--inspect-brk" "--livereload" "--open" "--port" "--with-mocks" "--with-mtx"" -- "$current") ) ;;
        esac
        if [[ "${#COMPREPLY[@]}" -gt 0 ]]; then
            compopt -o nospace
            return 0
        fi
    fi

    # Step 3.5: option-value completion — triggered when the previous word is a known option.
    case "$cmd" in
        bind)
            case "$previous" in
            --on) COMPREPLY=( $(compgen -W ""cf" "k8s" "kyma"" -- "$current") ) ; return 0 ;;
            --for) COMPREPLY=( $(compgen -W ""development" "production" "hybrid"" -- "$current") ) ; return 0 ;;
            --out) COMPREPLY=( $(compgen -f -- "$current") ) ; return 0 ;;
            --output-file) COMPREPLY=( $(compgen -f -- "$current") ) ; return 0 ;;
            --credentials) COMPREPLY=( $(compgen -f -- "$current" | grep -E '\.(json)$') ) ; return 0 ;;
            esac ;;
        bindings)
            case "$previous" in
            --as) COMPREPLY=( $(compgen -W ""json" "yaml"" -- "$current") ) ; return 0 ;;
            esac ;;
        build)
            case "$previous" in
            --for) COMPREPLY=( $(compgen -W ""hana" "helm" "java" "mtx" "mtx-extension" "mtx-sidecar" "nodejs"" -- "$current") ) ; return 0 ;;
            --log-level) COMPREPLY=( $(compgen -W ""debug" "info" "warn" "error"" -- "$current") ) ; return 0 ;;
            --project) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --dest) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --src) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --options-model) COMPREPLY=( $({ compgen -f -- "$current" | grep -E '\.(cds|json)$'; compgen -d -- "$current"; }) ) ; return 0 ;;
            esac ;;
        compile)
            case "$previous" in
            --from) COMPREPLY=( $(compgen -W ""cdl" "json" "yaml"" -- "$current") ) ; return 0 ;;
            --to) COMPREPLY=( $(compgen -W ""json" "yml" "edm" "edmx" "edmx-v2" "edmx-v4" "sql" "hdbtable" "hana" "cdl" "xsuaa" "openapi" "asyncapi"" -- "$current") ) ; return 0 ;;
            --for) COMPREPLY=( $(compgen -W ""odata" "sql"" -- "$current") ) ; return 0 ;;
            --dialect) COMPREPLY=( $(compgen -W ""sqlite" "h2" "postgres" "hana"" -- "$current") ) ; return 0 ;;
            --sql-dialect) COMPREPLY=( $(compgen -W ""sqlite" "h2" "postgres" "hana"" -- "$current") ) ; return 0 ;;
            --log-level) COMPREPLY=( $(compgen -W ""debug" "info" "warn" "error"" -- "$current") ) ; return 0 ;;
            --odata-version) COMPREPLY=( $(compgen -W ""4.0" "4.01"" -- "$current") ) ; return 0 ;;
            --flavor) COMPREPLY=( $(compgen -W ""sources" "files" "parsed" "xtended" "inferred"" -- "$current") ) ; return 0 ;;
            --service) COMPREPLY=( $(compgen -W ""all"" -- "$current") ) ; return 0 ;;
            --lang) COMPREPLY=( $(compgen -W ""all"" -- "$current") ) ; return 0 ;;
            --dest) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --openapi:config-file) COMPREPLY=( $(compgen -f -- "$current" | grep -E '\.(json)$') ) ; return 0 ;;
            esac ;;
        completion)
            case "$previous" in
            --shell) COMPREPLY=( $(compgen -W ""bash" "fish" "gitbash" "ps" "zsh"" -- "$current") ) ; return 0 ;;
            esac ;;
        deploy)
            case "$previous" in
            --to) COMPREPLY=( $(compgen -W ""sqlite" "hana"" -- "$current") ) ; return 0 ;;
            --on) COMPREPLY=( $(compgen -W ""cf" "k8s" "kyma"" -- "$current") ) ; return 0 ;;
            --for) COMPREPLY=( $(compgen -W ""development" "production" "hybrid"" -- "$current") ) ; return 0 ;;
            --out) COMPREPLY=( $(compgen -f -- "$current") ) ; return 0 ;;
            --vcap-file) COMPREPLY=( $(compgen -f -- "$current" | grep -E '\.(json)$') ) ; return 0 ;;
            --delta-from) COMPREPLY=( $(compgen -f -- "$current" | grep -E '\.(json)$') ) ; return 0 ;;
            esac ;;
        env)
            case "$previous" in
            --for) COMPREPLY=( $(compgen -W ""development" "production" "hybrid"" -- "$current") ) ; return 0 ;;
            esac ;;
        export)
            case "$previous" in
            --as) COMPREPLY=( $(compgen -W ""csn" "cdl"" -- "$current") ) ; return 0 ;;
            --for) COMPREPLY=( $(compgen -W ""npm" "mvn"" -- "$current") ) ; return 0 ;;
            --services) COMPREPLY=( $(compgen -W ""all"" -- "$current") ) ; return 0 ;;
            --from) COMPREPLY=( $({ compgen -f -- "$current" | grep -E '\.(cds|json)$'; compgen -d -- "$current"; }) ) ; return 0 ;;
            --to) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            esac ;;
        import)
            case "$previous" in
            --from) COMPREPLY=( $(compgen -W ""asyncapi" "edmx" "openapi"" -- "$current") ) ; return 0 ;;
            --as) COMPREPLY=( $(compgen -W ""cds" "csn" "json"" -- "$current") ) ; return 0 ;;
            --for) COMPREPLY=( $(compgen -W ""development" "production" "hybrid"" -- "$current") ) ; return 0 ;;
            --out) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --dependencies) COMPREPLY=( $(compgen -f -- "$current") ) ; return 0 ;;
            esac ;;
        init)
            case "$previous" in
            --java:package) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --base) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            esac ;;
        inspect)
            case "$previous" in
            --kind) COMPREPLY=( $(compgen -W ""entity" "aspect" "type" "service"" -- "$current") ) ; return 0 ;;
            --list) COMPREPLY=( $(compgen -W ""names" "elements" "keys" "associations" "compositions" "ids" "sources" "all"" -- "$current") ) ; return 0 ;;
            esac ;;
        parse)
            case "$previous" in
            --from) COMPREPLY=( $(compgen -W ""cdl" "json" "yaml"" -- "$current") ) ; return 0 ;;
            --to) COMPREPLY=( $(compgen -W ""json" "yml" "edm" "edmx" "edmx-v2" "edmx-v4" "sql" "hdbtable" "hana" "cdl" "xsuaa" "openapi" "asyncapi"" -- "$current") ) ; return 0 ;;
            --for) COMPREPLY=( $(compgen -W ""odata" "sql"" -- "$current") ) ; return 0 ;;
            --dialect) COMPREPLY=( $(compgen -W ""sqlite" "h2" "postgres" "hana"" -- "$current") ) ; return 0 ;;
            --sql-dialect) COMPREPLY=( $(compgen -W ""sqlite" "h2" "postgres" "hana"" -- "$current") ) ; return 0 ;;
            --log-level) COMPREPLY=( $(compgen -W ""debug" "info" "warn" "error"" -- "$current") ) ; return 0 ;;
            --odata-version) COMPREPLY=( $(compgen -W ""4.0" "4.01"" -- "$current") ) ; return 0 ;;
            --flavor) COMPREPLY=( $(compgen -W ""sources" "files" "parsed" "xtended" "inferred"" -- "$current") ) ; return 0 ;;
            --service) COMPREPLY=( $(compgen -W ""all"" -- "$current") ) ; return 0 ;;
            --lang) COMPREPLY=( $(compgen -W ""all"" -- "$current") ) ; return 0 ;;
            --dest) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --openapi:config-file) COMPREPLY=( $(compgen -f -- "$current" | grep -E '\.(json)$') ) ; return 0 ;;
            esac ;;
        repl)
            case "$previous" in
            --use) COMPREPLY=( $(compgen -W ""xl" "ql" "entities" "services"" -- "$current") ) ; return 0 ;;
            --run) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            -r) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            esac ;;
        run)
            case "$previous" in
            --to) COMPREPLY=( $(compgen -W ""odata" "fiori" "rest"" -- "$current") ) ; return 0 ;;
            --service) COMPREPLY=( $(compgen -W ""all"" -- "$current") ) ; return 0 ;;
            --from) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            -f) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --with) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            esac ;;
        serve)
            case "$previous" in
            --to) COMPREPLY=( $(compgen -W ""odata" "fiori" "rest"" -- "$current") ) ; return 0 ;;
            --service) COMPREPLY=( $(compgen -W ""all"" -- "$current") ) ; return 0 ;;
            --from) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            -f) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --with) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            esac ;;
        up)
            case "$previous" in
            --to) COMPREPLY=( $(compgen -W ""cf" "k8s" "kyma"" -- "$current") ) ; return 0 ;;
            --overlay) COMPREPLY=( $(compgen -f -- "$current" | grep -E '\.(mtaext)$') ) ; return 0 ;;
            esac ;;
        version)
            case "$previous" in
            --omit) COMPREPLY=( $(compgen -W ""dev" "optional" "peer"" -- "$current") ) ; return 0 ;;
            esac ;;
        watch)
            case "$previous" in
            --to) COMPREPLY=( $(compgen -W ""odata" "fiori" "rest"" -- "$current") ) ; return 0 ;;
            -2) COMPREPLY=( $(compgen -W ""odata" "fiori" "rest"" -- "$current") ) ; return 0 ;;
            --experimental-hot-reload) COMPREPLY=( $(compgen -W ""true" "false"" -- "$current") ) ; return 0 ;;
            --livereload) COMPREPLY=( $(compgen -W ""false"" -- "$current") ) ; return 0 ;;
            --from) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            -f) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --with) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            -w) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --include) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            --exclude) COMPREPLY=( $(compgen -d -- "$current") ) ; return 0 ;;
            esac ;;

    esac

    # Step 3.6: comma-separated option-value completion.
    # Splits $current on commas, filters out already-used values, prepends the prefix.
    case "$cmd" in
        add)
            case "$previous" in
            *)
                [[ "$previous" == -* ]] && return 0
                local prefix="" partial="" IFS=,
                if [[ "$current" == *,* ]]; then
                    prefix="${current%,*},"
                    partial="${current##*,}"
                else
                    partial="$current"
                fi
                local -a _used
                read -ra _used <<< "${prefix%,}"
                local _all=("ai" "ams" "app-frontend" "application-logging" "approuter" "attachments" "audit-logging" "cf-manifest" "cjs" "cloud-logging" "completion" "connectivity" "console" "data" "destination" "dynatrace" "enterprise-messaging" "enterprise-messaging-shared" "event-mesh" "event-mesh-shared" "extensibility" "extension" "file-based-messaging" "github-actions" "h2" "hana" "hana-serverless" "handler" "html5-repo" "http" "ias" "initial" "kafka" "kyma" "lint" "liquibase" "local-messaging" "malware-scanner" "mta" "mtx" "multitenancy" "notifications" "pipeline" "portal" "postgres" "react" "redis" "redis-messaging" "sample" "side-by-side-extensibility" "sqlite" "telemetry" "test" "tiny-sample" "toggles" "typer" "typescript" "ui5" "vue" "workzone" "workzone-standard" "xsuaa")
                for v in "${_all[@]}"; do
                    [[ " ${_used[*]} " == *" $v "* ]] && continue
                    [[ "$v" == "$partial"* ]] && COMPREPLY+=("$prefix$v")
                done
                [[ ${#COMPREPLY[@]} -gt 0 ]] && { compopt -o nospace; return 0; } ;;
            esac ;;
        init)
            case "$previous" in
            --add)
                local prefix="" partial="" IFS=,
                if [[ "$current" == *,* ]]; then
                    prefix="${current%,*},"
                    partial="${current##*,}"
                else
                    partial="$current"
                fi
                local -a _used
                read -ra _used <<< "${prefix%,}"
                local _all=("ai" "ams" "app-frontend" "application-logging" "approuter" "attachments" "audit-logging" "cf-manifest" "cjs" "cloud-logging" "completion" "connectivity" "console" "data" "destination" "dynatrace" "enterprise-messaging" "enterprise-messaging-shared" "event-mesh" "event-mesh-shared" "extensibility" "extension" "file-based-messaging" "github-actions" "h2" "hana" "hana-serverless" "handler" "html5-repo" "http" "ias" "initial" "kafka" "kyma" "lint" "liquibase" "local-messaging" "malware-scanner" "mta" "mtx" "multitenancy" "notifications" "pipeline" "portal" "postgres" "react" "redis" "redis-messaging" "sample" "side-by-side-extensibility" "sqlite" "telemetry" "test" "tiny-sample" "toggles" "typer" "typescript" "ui5" "vue" "workzone" "workzone-standard" "xsuaa")
                for v in "${_all[@]}"; do
                    [[ " ${_used[*]} " == *" $v "* ]] && continue
                    [[ "$v" == "$partial"* ]] && COMPREPLY+=("$prefix$v")
                done
                [[ ${#COMPREPLY[@]} -gt 0 ]] && { compopt -o nospace; return 0; } ;;
            esac ;;

    esac

    # Step 4: file-sentinel positionals — fill COMPREPLY with files and return.
    case "$cmd" in
            compile) COMPREPLY=( $({ compgen -f -- "$current" | grep -E '\.(cds|json)$'; compgen -d -- "$current"; }) ) ;;
            deploy) COMPREPLY=( $({ compgen -f -- "$current" | grep -E '\.(cds|json)$'; compgen -d -- "$current"; }) ) ;;
            export) COMPREPLY=( $({ compgen -f -- "$current" | grep -E '\.(cds|json)$'; compgen -d -- "$current"; }) ) ;;
            import) COMPREPLY=( $(compgen -f -- "$current" | grep -E '\.(json|xml|edmx)$') ) ;;
            inspect) COMPREPLY=( $({ compgen -f -- "$current" | grep -E '\.(cds|json)$'; compgen -d -- "$current"; }) ) ;;
            lint) COMPREPLY=( $({ compgen -f -- "$current" | grep -E '\.(js|ts|cds)$'; compgen -d -- "$current"; }) ) ;;
            minify) COMPREPLY=( $({ compgen -f -- "$current" | grep -E '\.(cds|json)$'; compgen -d -- "$current"; }) ) ;;
            parse) COMPREPLY=( $({ compgen -f -- "$current" | grep -E '\.(cds|json)$'; compgen -d -- "$current"; }) ) ;;
            repl) COMPREPLY=( $(compgen -d -- "$current") ) ;;
            run) COMPREPLY=( $(compgen -d -- "$current") ) ;;
            serve) COMPREPLY=( $(compgen -d -- "$current") ) ;;
            watch) COMPREPLY=( $(compgen -d -- "$current") ) ;;
    esac
    if [[ "${#COMPREPLY[@]}" -gt 0 ]]; then
        compopt -o nospace
        return 0
    fi

    # Step 4.6: string positionals (e.g. cds help <tab>).
    case "$cmd" in
            help) COMPREPLY=( $(compgen -W ""add" "bind" "bindings" "build" "compile" "completion" "debug" "deploy" "env" "eval" "export" "gen" "help" "import" "init" "inspect" "lint" "login" "logout" "minify" "mock" "parse" "pull" "push" "repl" "run" "serve" "subscribe" "test" "unsubscribe" "up" "upgrade" "upgrade-tenant" "version" "watch"" -- "$current") ) ;;
    esac
    if [[ "${#COMPREPLY[@]}" -gt 0 ]]; then
        compopt -o nospace
        return 0
    fi

    # Step 5: dynamic fallback — calls 'cds completion' for subcommands whose arguments
    # cannot be determined statically (e.g. service names, model names, unknown flags).
    # Single-quoting $previous/$current prevents bare word 'h' from being interpreted
    # as the 'help' shortcut by the completion handler before it is processed.
    local options
    options=$($CDS_COMMAND completion --shell bash --prev "'$previous'" --curr "'$current'" --line "'${COMP_WORDS[*]}'")
    COMPREPLY=( $(compgen -W "${options}" -- "${current}") )
    compopt -o nospace
    return 0
}

# Register the completion function for the 'cds' command.
complete -F _completeCds "$CDS_COMMAND"
