#compdef _tkn tkn




function _tkn {
  local -a commands

  _arguments -C \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "clustertask:Manage ClusterTasks"
      "clustertriggerbinding:Manage ClusterTriggerBindings"
      "completion:Prints shell completion scripts"
      "condition:Manage Conditions"
      "eventlistener:Manage EventListeners"
      "help:Help about any command"
      "hub:Interact with tekton hub"
      "pipeline:Manage pipelines"
      "pipelinerun:Manage PipelineRuns"
      "resource:Manage pipeline resources"
      "task:Manage Tasks"
      "taskrun:Manage TaskRuns"
      "triggerbinding:Manage TriggerBindings"
      "triggertemplate:Manage TriggerTemplates"
      "version:Prints version information"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  clustertask|clustertasks|ct)
    _tkn_clustertask
    ;;
  clustertriggerbinding|clustertriggerbindings|ctb)
    _tkn_clustertriggerbinding
    ;;
  completion)
    _tkn_completion
    ;;
  condition|cond|conditions)
    _tkn_condition
    ;;
  eventlistener|el|eventlisteners)
    _tkn_eventlistener
    ;;
  help)
    _tkn_help
    ;;
  hub)
    _tkn_hub
    ;;
  pipeline|p|pipelines)
    _tkn_pipeline
    ;;
  pipelinerun|pipelineruns|pr)
    _tkn_pipelinerun
    ;;
  resource|res|resources)
    _tkn_resource
    ;;
  task|t|tasks)
    _tkn_task
    ;;
  taskrun|taskruns|tr)
    _tkn_taskrun
    ;;
  triggerbinding|tb|triggerbindings)
    _tkn_triggerbinding
    ;;
  triggertemplate|triggertemplates|tt)
    _tkn_triggertemplate
    ;;
  version)
    _tkn_version
    ;;
  esac
}


function _tkn_clustertask {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "delete:Delete ClusterTasks in a cluster"
      "describe:Describe a ClusterTask"
      "list:Lists ClusterTasks"
      "start:Start ClusterTasks"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  delete|rm)
    _tkn_clustertask_delete
    ;;
  describe|desc)
    _tkn_clustertask_describe
    ;;
  list|ls)
    _tkn_clustertask_list
    ;;
  start)
    _tkn_clustertask_start
    ;;
  esac
}

function _tkn_clustertask_delete {
  _arguments \
    '--all[Delete all ClusterTasks (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '--trs[Whether to delete ClusterTask(s) and related resources (TaskRuns) (default: false)]' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_clustertasks'
}

function _tkn_clustertask_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_clustertasks'
}

function _tkn_clustertask_list {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}

function _tkn_clustertask_start {
  _arguments \
    '--dry-run[preview TaskRun without running it]' \
    '(*-i *--inputresource)'{\*-i,\*--inputresource}'[pass the input resource name and ref as name=ref]:()' \
    '(*-l *--labels)'{\*-l,\*--labels}'[pass labels as label=value.]:()' \
    '(-L --last)'{-L,--last}'[re-run the ClusterTask using last TaskRun values]' \
    '--output[format of TaskRun dry-run (yaml or json)]:()' \
    '(*-o *--outputresource)'{\*-o,\*--outputresource}'[pass the output resource name and ref as name=ref]:()' \
    '(*-p *--param)'{\*-p,\*--param}'[pass the param as key=value for string type, or key=value1,value2,... for array type]:()' \
    '--pod-template[local or remote file containing a PodTemplate definition]:()' \
    '--prefix-name[specify a prefix for the TaskRun name (must be lowercase alphanumeric characters)]:()' \
    '(-s --serviceaccount)'{-s,--serviceaccount}'[pass the serviceaccount name]: :__kubectl_get_serviceaccount' \
    '--showlog[show logs right after starting the ClusterTask]' \
    '--timeout[timeout for TaskRun]:()' \
    '--use-param-defaults[use default parameter values without prompting for input]' \
    '--use-taskrun[specify a TaskRun name to use its values to re-run the TaskRun]: :__tkn_get_taskrun' \
    '(*-w *--workspace)'{\*-w,\*--workspace}'[pass one or more workspaces to map to the corresponding physical volumes as name=name,claimName=pvcName or name=name,emptyDir=]:()' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_clustertasks'
}


function _tkn_clustertriggerbinding {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "delete:Delete ClusterTriggerBindings"
      "describe:Describes a ClusterTriggerBinding"
      "list:Lists ClusterTriggerBindings in a namespace"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  delete|rm)
    _tkn_clustertriggerbinding_delete
    ;;
  describe|desc)
    _tkn_clustertriggerbinding_describe
    ;;
  list|ls)
    _tkn_clustertriggerbinding_list
    ;;
  esac
}

function _tkn_clustertriggerbinding_delete {
  _arguments \
    '--all[Delete all ClusterTriggerBindings (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_clustertriggerbinding'
}

function _tkn_clustertriggerbinding_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_clustertriggerbindings'
}

function _tkn_clustertriggerbinding_list {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}

function _tkn_completion {
  _arguments \
    '(-h --help)'{-h,--help}'[help for completion]' \
    '1: :("bash" "zsh")'
}


function _tkn_condition {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "delete:Delete Conditions in a namespace"
      "describe:Describe Conditions in a namespace"
      "list:Lists Conditions in a namespace"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  delete|rm)
    _tkn_condition_delete
    ;;
  describe|desc)
    _tkn_condition_describe
    ;;
  list|ls)
    _tkn_condition_list
    ;;
  esac
}

function _tkn_condition_delete {
  _arguments \
    '--all[Delete all Conditions in a namespace (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_condition'
}

function _tkn_condition_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_condition'
}

function _tkn_condition_list {
  _arguments \
    '(-A --all-namespaces)'{-A,--all-namespaces}'[list Conditions from all namespaces]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}


function _tkn_eventlistener {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "delete:Delete EventListeners in a namespace"
      "describe:Describe EventListener in a namespace"
      "list:Lists EventListeners in a namespace"
      "logs:Show EventListener logs"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  delete|rm)
    _tkn_eventlistener_delete
    ;;
  describe|desc)
    _tkn_eventlistener_describe
    ;;
  list|ls)
    _tkn_eventlistener_list
    ;;
  logs)
    _tkn_eventlistener_logs
    ;;
  esac
}

function _tkn_eventlistener_delete {
  _arguments \
    '--all[Delete all EventListeners in a namespace (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_eventlistener'
}

function _tkn_eventlistener_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_eventlistener'
}

function _tkn_eventlistener_list {
  _arguments \
    '(-A --all-namespaces)'{-A,--all-namespaces}'[list EventListeners from all namespaces]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}

function _tkn_eventlistener_logs {
  _arguments \
    '(-t --tail)'{-t,--tail}'[Number of most recent log lines to show. Specify -1 for all logs from each pod.]:()' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_eventlistener'
}

function _tkn_help {
  _arguments
}


function _tkn_hub {
  local -a commands

  _arguments -C \
    '--api-server[Hub API Server URL]:()' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "downgrade:Downgrade an installed resource"
      "get:Get resource manifest by its name, kind, catalog, and version"
      "info:Display info of resource by its name, kind, catalog, and version"
      "install:Install a resource from a catalog by its kind, name and version"
      "reinstall:Reinstall a resource by its kind and name"
      "search:Search resource by a combination of name, kind, and tags"
      "upgrade:Upgrade an installed resource"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  downgrade)
    _tkn_hub_downgrade
    ;;
  get)
    _tkn_hub_get
    ;;
  info)
    _tkn_hub_info
    ;;
  install)
    _tkn_hub_install
    ;;
  reinstall)
    _tkn_hub_reinstall
    ;;
  search)
    _tkn_hub_search
    ;;
  upgrade)
    _tkn_hub_upgrade
    ;;
  esac
}


function _tkn_hub_downgrade {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[Name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[Kubectl config file (default: $HOME/.kube/config)]:()' \
    '(-n --namespace)'{-n,--namespace}'[Namespace to use (default: from $KUBECONFIG)]:()' \
    '--to[Version of Resource]:()' \
    '--api-server[Hub API Server URL]:()' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "task:Downgrade an installed Task by its name to a lower version"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  task)
    _tkn_hub_downgrade_task
    ;;
  esac
}

function _tkn_hub_downgrade_task {
  _arguments \
    '--api-server[Hub API Server URL]:()' \
    '(-c --context)'{-c,--context}'[Name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[Kubectl config file (default: $HOME/.kube/config)]:()' \
    '(-n --namespace)'{-n,--namespace}'[Namespace to use (default: from $KUBECONFIG)]:()' \
    '--to[Version of Resource]:()'
}


function _tkn_hub_get {
  local -a commands

  _arguments -C \
    '--from[Name of Catalog to which resource belongs to.]:()' \
    '--version[Version of Resource]:()' \
    '--api-server[Hub API Server URL]:()' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "pipeline:Get Pipeline by name, catalog and version"
      "task:Get Task by name, catalog and version"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  pipeline)
    _tkn_hub_get_pipeline
    ;;
  task)
    _tkn_hub_get_task
    ;;
  esac
}

function _tkn_hub_get_pipeline {
  _arguments \
    '--api-server[Hub API Server URL]:()' \
    '--from[Name of Catalog to which resource belongs to.]:()' \
    '--version[Version of Resource]:()'
}

function _tkn_hub_get_task {
  _arguments \
    '--as-clustertask[Get the Task as ClusterTask]' \
    '--api-server[Hub API Server URL]:()' \
    '--from[Name of Catalog to which resource belongs to.]:()' \
    '--version[Version of Resource]:()'
}


function _tkn_hub_info {
  local -a commands

  _arguments -C \
    '--from[Name of Catalog to which resource belongs.]:()' \
    '--version[Version of Resource]:()' \
    '--api-server[Hub API Server URL]:()' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "task:Display info of Task by its name, catalog and version"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  task)
    _tkn_hub_info_task
    ;;
  esac
}

function _tkn_hub_info_task {
  _arguments \
    '--api-server[Hub API Server URL]:()' \
    '--from[Name of Catalog to which resource belongs.]:()' \
    '--version[Version of Resource]:()'
}


function _tkn_hub_install {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[Name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '--from[Name of Catalog to which resource belongs.]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[Kubectl config file (default: $HOME/.kube/config)]:()' \
    '(-n --namespace)'{-n,--namespace}'[Namespace to use (default: from $KUBECONFIG)]:()' \
    '--version[Version of Resource]:()' \
    '--api-server[Hub API Server URL]:()' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "task:Install Task from a catalog by its name and version"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  task)
    _tkn_hub_install_task
    ;;
  esac
}

function _tkn_hub_install_task {
  _arguments \
    '--api-server[Hub API Server URL]:()' \
    '(-c --context)'{-c,--context}'[Name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '--from[Name of Catalog to which resource belongs.]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[Kubectl config file (default: $HOME/.kube/config)]:()' \
    '(-n --namespace)'{-n,--namespace}'[Namespace to use (default: from $KUBECONFIG)]:()' \
    '--version[Version of Resource]:()'
}


function _tkn_hub_reinstall {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[Name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '--from[Name of Catalog to which resource belongs.]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[Kubectl config file (default: $HOME/.kube/config)]:()' \
    '(-n --namespace)'{-n,--namespace}'[Namespace to use (default: from $KUBECONFIG)]:()' \
    '--version[Version of Resource]:()' \
    '--api-server[Hub API Server URL]:()' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "task:Reinstall a Task by its name"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  task)
    _tkn_hub_reinstall_task
    ;;
  esac
}

function _tkn_hub_reinstall_task {
  _arguments \
    '--api-server[Hub API Server URL]:()' \
    '(-c --context)'{-c,--context}'[Name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '--from[Name of Catalog to which resource belongs.]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[Kubectl config file (default: $HOME/.kube/config)]:()' \
    '(-n --namespace)'{-n,--namespace}'[Namespace to use (default: from $KUBECONFIG)]:()' \
    '--version[Version of Resource]:()'
}

function _tkn_hub_search {
  _arguments \
    '*--kinds[Accepts a comma separated list of kinds]:()' \
    '(-l --limit)'{-l,--limit}'[Max number of resources to fetch]:()' \
    '--match[Accept type of search. '\''exact'\'' or '\''contains'\''.]:()' \
    '(-o --output)'{-o,--output}'[Accepts output format: \[table, json\]]:()' \
    '*--tags[Accepts a comma separated list of tags]:()' \
    '--api-server[Hub API Server URL]:()'
}


function _tkn_hub_upgrade {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[Name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[Kubectl config file (default: $HOME/.kube/config)]:()' \
    '(-n --namespace)'{-n,--namespace}'[Namespace to use (default: from $KUBECONFIG)]:()' \
    '--to[Version of Resource]:()' \
    '--api-server[Hub API Server URL]:()' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "task:Upgrade a Task by its name"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  task)
    _tkn_hub_upgrade_task
    ;;
  esac
}

function _tkn_hub_upgrade_task {
  _arguments \
    '--api-server[Hub API Server URL]:()' \
    '(-c --context)'{-c,--context}'[Name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[Kubectl config file (default: $HOME/.kube/config)]:()' \
    '(-n --namespace)'{-n,--namespace}'[Namespace to use (default: from $KUBECONFIG)]:()' \
    '--to[Version of Resource]:()'
}


function _tkn_pipeline {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "delete:Delete Pipelines in a namespace"
      "describe:Describes a Pipeline in a namespace"
      "list:Lists Pipelines in a namespace"
      "logs:Show Pipeline logs"
      "start:Start Pipelines"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  delete|rm)
    _tkn_pipeline_delete
    ;;
  describe|desc)
    _tkn_pipeline_describe
    ;;
  list|ls)
    _tkn_pipeline_list
    ;;
  logs)
    _tkn_pipeline_logs
    ;;
  start)
    _tkn_pipeline_start
    ;;
  esac
}

function _tkn_pipeline_delete {
  _arguments \
    '--all[Delete all Pipelines in a namespace (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--prs[Whether to delete Pipeline(s) and related resources (PipelineRuns) (default: false)]' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipeline'
}

function _tkn_pipeline_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipeline'
}

function _tkn_pipeline_list {
  _arguments \
    '(-A --all-namespaces)'{-A,--all-namespaces}'[list Pipelines from all namespaces]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}

function _tkn_pipeline_logs {
  _arguments \
    '(-a --all)'{-a,--all}'[show all logs including init steps injected by tekton]' \
    '(-f --follow)'{-f,--follow}'[stream live logs]' \
    '(-L --last)'{-L,--last}'[show logs for last PipelineRun]' \
    '--limit[lists number of PipelineRuns]:()' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipeline'
}

function _tkn_pipeline_start {
  _arguments \
    '--dry-run[preview PipelineRun without running it]' \
    '(-f --filename)'{-f,--filename}'[local or remote file name containing a Pipeline definition to start a PipelineRun]:()' \
    '(*-l *--labels)'{\*-l,\*--labels}'[pass labels as label=value.]:()' \
    '(-L --last)'{-L,--last}'[re-run the Pipeline using last PipelineRun values]' \
    '--output[format of PipelineRun dry-run (yaml or json)]:()' \
    '(*-p *--param)'{\*-p,\*--param}'[pass the param as key=value for string type, or key=value1,value2,... for array type]:()' \
    '--pod-template[local or remote file containing a PodTemplate definition]:()' \
    '--prefix-name[specify a prefix for the PipelineRun name (must be lowercase alphanumeric characters)]:()' \
    '(*-r *--resource)'{\*-r,\*--resource}'[pass the resource name and ref as name=ref]:()' \
    '(-s --serviceaccount)'{-s,--serviceaccount}'[pass the serviceaccount name]: :__kubectl_get_serviceaccount' \
    '--showlog[show logs right after starting the Pipeline]' \
    '*--task-serviceaccount[pass the service account corresponding to the task]: :__kubectl_get_serviceaccount' \
    '--timeout[timeout for PipelineRun]:()' \
    '--use-param-defaults[use default parameter values without prompting for input]' \
    '--use-pipelinerun[use this pipelinerun values to re-run the pipeline. ]: :__tkn_get_pipelinerun' \
    '(*-w *--workspace)'{\*-w,\*--workspace}'[pass the workspace.]:()' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipeline'
}


function _tkn_pipelinerun {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "cancel:Cancel a PipelineRun in a namespace"
      "delete:Delete PipelineRuns in a namespace"
      "describe:Describe a PipelineRun in a namespace"
      "list:Lists PipelineRuns in a namespace"
      "logs:Show the logs of a PipelineRun"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  cancel)
    _tkn_pipelinerun_cancel
    ;;
  delete|rm)
    _tkn_pipelinerun_delete
    ;;
  describe|desc)
    _tkn_pipelinerun_describe
    ;;
  list|ls)
    _tkn_pipelinerun_list
    ;;
  logs)
    _tkn_pipelinerun_logs
    ;;
  esac
}

function _tkn_pipelinerun_cancel {
  _arguments \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipelinerun'
}

function _tkn_pipelinerun_delete {
  _arguments \
    '--all[Delete all PipelineRuns in a namespace (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '--keep[Keep n most recent number of PipelineRuns]:()' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '(-p --pipeline)'{-p,--pipeline}'[The name of a Pipeline whose PipelineRuns should be deleted (does not delete the Pipeline)]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipelinerun'
}

function _tkn_pipelinerun_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-F --fzf)'{-F,--fzf}'[use fzf to select a PipelineRun to describe]' \
    '(-L --last)'{-L,--last}'[show description for last PipelineRun]' \
    '--limit[lists number of PipelineRuns when selecting a PipelineRun to describe]:()' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipelinerun'
}

function _tkn_pipelinerun_list {
  _arguments \
    '(-A --all-namespaces)'{-A,--all-namespaces}'[list PipelineRuns from all namespaces]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--label[A selector (label query) to filter on, supports '\''='\'', '\''=='\'', and '\''!='\'']:()' \
    '--limit[limit PipelineRuns listed (default: return all PipelineRuns)]:()' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--reverse[list PipelineRuns in reverse order]' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}

function _tkn_pipelinerun_logs {
  _arguments \
    '(-a --all)'{-a,--all}'[show all logs including init steps injected by tekton]' \
    '(-f --follow)'{-f,--follow}'[stream live logs]' \
    '(-F --fzf)'{-F,--fzf}'[use fzf to select a PipelineRun]' \
    '(-L --last)'{-L,--last}'[show logs for last PipelineRun]' \
    '--limit[lists number of PipelineRuns]:()' \
    '(*-t *--task)'{\*-t,\*--task}'[show logs for mentioned Tasks only]:()' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipelinerun'
}


function _tkn_resource {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "create:Create a pipeline resource in a namespace"
      "delete:Delete pipeline resources in a namespace"
      "describe:Describes a pipeline resource in a namespace"
      "list:Lists pipeline resources in a namespace"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  create)
    _tkn_resource_create
    ;;
  delete|rm)
    _tkn_resource_delete
    ;;
  describe|desc)
    _tkn_resource_describe
    ;;
  list|ls)
    _tkn_resource_list
    ;;
  esac
}

function _tkn_resource_create {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}

function _tkn_resource_delete {
  _arguments \
    '--all[Delete all PipelineResources in a namespace (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipelineresource'
}

function _tkn_resource_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_pipelineresource'
}

function _tkn_resource_list {
  _arguments \
    '(-A --all-namespaces)'{-A,--all-namespaces}'[list pipeline resources from all namespaces]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-t --type)'{-t,--type}'[Pipeline resource type]:()' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}


function _tkn_task {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "delete:Delete Tasks in a namespace"
      "describe:Describe a Task in a namespace"
      "list:Lists Tasks in a namespace"
      "logs:Show Task logs"
      "start:Start Tasks"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  delete|rm)
    _tkn_task_delete
    ;;
  describe|desc)
    _tkn_task_describe
    ;;
  list|ls)
    _tkn_task_list
    ;;
  logs)
    _tkn_task_logs
    ;;
  start)
    _tkn_task_start
    ;;
  esac
}

function _tkn_task_delete {
  _arguments \
    '--all[Delete all Tasks in a namespace (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '--trs[Whether to delete Task(s) and related resources (TaskRuns) (default: false)]' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_task'
}

function _tkn_task_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_task'
}

function _tkn_task_list {
  _arguments \
    '(-A --all-namespaces)'{-A,--all-namespaces}'[list Tasks from all namespaces]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}

function _tkn_task_logs {
  _arguments \
    '(-a --all)'{-a,--all}'[show all logs including init steps injected by tekton]' \
    '(-f --follow)'{-f,--follow}'[stream live logs]' \
    '(-L --last)'{-L,--last}'[show logs for last TaskRun]' \
    '--limit[lists number of TaskRuns]:()' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_task'
}

function _tkn_task_start {
  _arguments \
    '--dry-run[preview TaskRun without running it]' \
    '(-f --filename)'{-f,--filename}'[local or remote file name containing a Task definition to start a TaskRun]:()' \
    '(*-i *--inputresource)'{\*-i,\*--inputresource}'[pass the input resource name and ref as name=ref]:()' \
    '(*-l *--labels)'{\*-l,\*--labels}'[pass labels as label=value.]:()' \
    '(-L --last)'{-L,--last}'[re-run the Task using last TaskRun values]' \
    '--output[format of TaskRun dry-run (yaml or json)]:()' \
    '(*-o *--outputresource)'{\*-o,\*--outputresource}'[pass the output resource name and ref as name=ref]:()' \
    '(*-p *--param)'{\*-p,\*--param}'[pass the param as key=value for string type, or key=value1,value2,... for array type]:()' \
    '--pod-template[local or remote file containing a PodTemplate definition]:()' \
    '--prefix-name[specify a prefix for the TaskRun name (must be lowercase alphanumeric characters)]:()' \
    '(-s --serviceaccount)'{-s,--serviceaccount}'[pass the serviceaccount name]: :__kubectl_get_serviceaccount' \
    '--showlog[show logs right after starting the Task]' \
    '--timeout[timeout for TaskRun]:()' \
    '--use-param-defaults[use default parameter values without prompting for input]' \
    '--use-taskrun[specify a TaskRun name to use its values to re-run the TaskRun]: :__tkn_get_taskrun' \
    '(*-w *--workspace)'{\*-w,\*--workspace}'[pass the workspace.]:()' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_task'
}


function _tkn_taskrun {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "cancel:Cancel a TaskRun in a namespace"
      "delete:Delete TaskRuns in a namespace"
      "describe:Describe a TaskRun in a namespace"
      "list:Lists TaskRuns in a namespace"
      "logs:Show TaskRuns logs"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  cancel)
    _tkn_taskrun_cancel
    ;;
  delete|rm)
    _tkn_taskrun_delete
    ;;
  describe|desc)
    _tkn_taskrun_describe
    ;;
  list|ls)
    _tkn_taskrun_list
    ;;
  logs)
    _tkn_taskrun_logs
    ;;
  esac
}

function _tkn_taskrun_cancel {
  _arguments \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_taskrun'
}

function _tkn_taskrun_delete {
  _arguments \
    '--all[Delete all TaskRuns in a namespace (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '--keep[Keep n most recent number of TaskRuns]:()' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '(-t --task)'{-t,--task}'[The name of a Task whose TaskRuns should be deleted (does not delete the task)]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_taskrun'
}

function _tkn_taskrun_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-F --fzf)'{-F,--fzf}'[use fzf to select a taskrun to describe]' \
    '(-L --last)'{-L,--last}'[show description for last TaskRun]' \
    '--limit[lists number of TaskRuns when selecting a TaskRun to describe]:()' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_taskrun'
}

function _tkn_taskrun_list {
  _arguments \
    '(-A --all-namespaces)'{-A,--all-namespaces}'[list TaskRuns from all namespaces]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--label[A selector (label query) to filter on, supports '\''='\'', '\''=='\'', and '\''!='\'']:()' \
    '--limit[limit TaskRuns listed (default: return all TaskRuns)]:()' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--reverse[list TaskRuns in reverse order]' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}

function _tkn_taskrun_logs {
  _arguments \
    '(-a --all)'{-a,--all}'[show all logs including init steps injected by tekton]' \
    '(-f --follow)'{-f,--follow}'[stream live logs]' \
    '(-F --fzf)'{-F,--fzf}'[use fzf to select a TaskRun]' \
    '(-L --last)'{-L,--last}'[show logs for last TaskRun]' \
    '--limit[lists number of TaskRuns]:()' \
    '(*-s *--step)'{\*-s,\*--step}'[show logs for mentioned steps only]:()' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_taskrun'
}


function _tkn_triggerbinding {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "delete:Delete TriggerBindings in a namespace"
      "describe:Describes a TriggerBinding in a namespace"
      "list:Lists TriggerBindings in a namespace"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  delete|rm)
    _tkn_triggerbinding_delete
    ;;
  describe|desc)
    _tkn_triggerbinding_describe
    ;;
  list|ls)
    _tkn_triggerbinding_list
    ;;
  esac
}

function _tkn_triggerbinding_delete {
  _arguments \
    '--all[Delete all TriggerBindings in a namespace (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_triggerbinding'
}

function _tkn_triggerbinding_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_triggerbindings'
}

function _tkn_triggerbinding_list {
  _arguments \
    '(-A --all-namespaces)'{-A,--all-namespaces}'[list TriggerBindings from all namespaces]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}


function _tkn_triggertemplate {
  local -a commands

  _arguments -C \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "delete:Delete TriggerTemplates in a namespace"
      "describe:Describes a TriggerTemplate in a namespace"
      "list:Lists TriggerTemplates in a namespace"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  delete|rm)
    _tkn_triggertemplate_delete
    ;;
  describe|desc)
    _tkn_triggertemplate_describe
    ;;
  list|ls)
    _tkn_triggertemplate_list
    ;;
  esac
}

function _tkn_triggertemplate_delete {
  _arguments \
    '--all[Delete all TriggerTemplates in a namespace (default: false)]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-f --force)'{-f,--force}'[Whether to force deletion (default: false)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_triggertemplate'
}

function _tkn_triggertemplate_describe {
  _arguments \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]' \
    '1: :__tkn_get_triggertemplate'
}

function _tkn_triggertemplate_list {
  _arguments \
    '(-A --all-namespaces)'{-A,--all-namespaces}'[list TriggerTemplates from all namespaces]' \
    '--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
    '--no-headers[do not print column headers with output (default print column headers with output)]' \
    '(-o --output)'{-o,--output}'[Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.]:()' \
    '--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]:filename:_files' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to use (default: from $KUBECONFIG)]: :__kubectl_get_namespace' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}

function _tkn_version {
  _arguments \
    '--check[check if a newer version is available]' \
    '(-c --context)'{-c,--context}'[name of the kubeconfig context to use (default: kubectl config current-context)]:()' \
    '(-k --kubeconfig)'{-k,--kubeconfig}'[kubectl config file (default: $HOME/.kube/config)]: :_filedir' \
    '(-n --namespace)'{-n,--namespace}'[namespace to check installed controller version]:()' \
    '(-C --no-color)'{-C,--no-color}'[disable coloring (default: false)]'
}


# Custom function for Completions
function __tkn_get_object() {
    local type=$1
    local util=$2
    local template begin tkn_out
    template="{{ range .items  }}{{ .metadata.name }} {{ end }}"

    if [[ ${util} == "kubectl" ]];then
        tkn_out=($(kubectl get ${type} -o template --template="${template}" 2>/dev/null))
    elif [[ ${util} == "tkn" ]];then
        tkn_out=($(tkn ${type} ls -o template --template="${template}" 2>/dev/null))
    fi

    if [[ -n ${tkn_out} ]]; then
        [[ -n ${BASH_VERSION} ]] && COMPREPLY=( $( compgen -W "${tkn_out}" -- "$cur" ) )
        [[ -n ${ZSH_VERSION} ]] && compadd ${tkn_out}
    fi
}

function __kubectl_get_namespace() { __tkn_get_object namespace kubectl ;}
function __kubectl_get_serviceaccount() { __tkn_get_object serviceaccount kubectl ;}
function __tkn_get_pipeline() { __tkn_get_object pipeline tkn ;}
function __tkn_get_pipelinerun() { __tkn_get_object pipelinerun tkn ;}
function __tkn_get_task() { __tkn_get_object task tkn ;}
function __tkn_get_taskrun() { __tkn_get_object taskrun tkn ;}
function __tkn_get_pipelineresource() { __tkn_get_object resource tkn ;}
function __tkn_get_clustertasks() { __tkn_get_object clustertasks tkn ;}
