#compdef _kubeone kubeone


function _kubeone {
  local -a commands

  _arguments -C \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "apply:Reconcile the cluster"
      "completion:Generates completion scripts for bash and zsh"
      "config:Commands for working with the KubeOneCluster configuration manifests"
      "document:Generates documentation"
      "help:Help about any command"
      "install:Install Kubernetes"
      "kubeconfig:Download the kubeconfig file from master"
      "proxy:Proxy to the kube-apiserver using SSH tunnel"
      "reset:Revert changes"
      "status:Status of the cluster"
      "upgrade:Upgrade Kubernetes"
      "version:Display KubeOne version"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  apply)
    _kubeone_apply
    ;;
  completion)
    _kubeone_completion
    ;;
  config)
    _kubeone_config
    ;;
  document)
    _kubeone_document
    ;;
  help)
    _kubeone_help
    ;;
  install)
    _kubeone_install
    ;;
  kubeconfig)
    _kubeone_kubeconfig
    ;;
  proxy)
    _kubeone_proxy
    ;;
  reset)
    _kubeone_reset
    ;;
  status)
    _kubeone_status
    ;;
  upgrade)
    _kubeone_upgrade
    ;;
  version)
    _kubeone_version
    ;;
  esac
}

function _kubeone_apply {
  _arguments \
    '(-y --auto-approve)'{-y,--auto-approve}'[auto approve plan]' \
    '(-b --backup)'{-b,--backup}'[path to where the PKI backup .tar.gz file should be placed (default: location of cluster config file)]:' \
    '--force-install[use force to install new binary versions (!dangerous!)]' \
    '--force-upgrade[force start upgrade process]' \
    '--no-init[don'\''t initialize the cluster (only install binaries)]' \
    '--upgrade-machine-deployments[upgrade MachineDeployments objects]' \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_completion {
  _arguments \
    '(-h --help)'{-h,--help}'[help for completion]' \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]' \
    '1: :("bash" "zsh")'
}


function _kubeone_config {
  local -a commands

  _arguments -C \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "machinedeployments:Print the manifest for creating MachineDeployments"
      "migrate:Migrate the v1alpha1 KubeOneCluster manifest to the v1beta1 version"
      "print:Print an example configuration manifest"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  machinedeployments)
    _kubeone_config_machinedeployments
    ;;
  migrate)
    _kubeone_config_migrate
    ;;
  print)
    _kubeone_config_print
    ;;
  esac
}

function _kubeone_config_machinedeployments {
  _arguments \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_config_migrate {
  _arguments \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_config_print {
  _arguments \
    '--api-endpoint-host[API endpoint hostname or address]:' \
    '--api-endpoint-port[API endpoint port]:' \
    '(-n --cluster-name)'{-n,--cluster-name}'[cluster name]:' \
    '--control-plane-hosts[control plane hosts in format of comma-separated key:value list, example: publicAddress:192.168.0.100,privateAddress:192.168.1.100,sshUsername:ubuntu,sshPort:22. Use quoted string of space separated values for multiple hosts]:' \
    '--deploy-machine-controller[deploy kubermatic machine-controller]' \
    '--enable-dynamic-audit-log[enable DynamicAuditLog]' \
    '--enable-metrics-server[enable metrics-server]' \
    '--enable-openid-connect[enable OpenID Connect authentication]' \
    '--enable-pod-node-selector[enable PodNodeSelector admission plugin]' \
    '--enable-pod-presets[enable PodPresets]' \
    '--enable-pod-security-policy[enable PodSecurityPolicy]' \
    '--enable-static-audit-log[enable StaticAuditLog]' \
    '(-f --full)'{-f,--full}'[show full manifest]' \
    '(-k --kubernetes-version)'{-k,--kubernetes-version}'[Kubernetes version]:' \
    '--node-port-range[Port range to be used for NodePort]:' \
    '--pod-subnet[Subnet to be used for pods networking]:' \
    '(-p --provider)'{-p,--provider}'[cloud provider name (aws, digitalocean, gce, hetzner, packet, openstack, vsphere, none)]:' \
    '--proxy-http[HTTP proxy to be used for provisioning and Docker]:' \
    '--proxy-https[HTTPs proxy to be used for provisioning and Docker]:' \
    '--proxy-no-proxy[No Proxy to be used for provisioning and Docker]:' \
    '--service-dns[Domain name to be used for Services]:' \
    '--service-subnet[Subnet to be used for Services]:' \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_document {
  _arguments \
    '(-o --output-dir)'{-o,--output-dir}'[Directory to populate with documentation]:' \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]' \
    '1: :("man" "md" "rest" "yaml")'
}

function _kubeone_help {
  _arguments \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_install {
  _arguments \
    '(-b --backup)'{-b,--backup}'[path to where the PKI backup .tar.gz file should be placed (default: location of cluster config file)]:' \
    '--force[use force to install new binary versions (!dangerous!)]' \
    '--no-init[don'\''t initialize the cluster (only install binaries)]' \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_kubeconfig {
  _arguments \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_proxy {
  _arguments \
    '--listen[SSH tunnel HTTP proxy bind address]:' \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_reset {
  _arguments \
    '--destroy-workers[destroy all worker machines before resetting the cluster]' \
    '--remove-binaries[remove kubernetes binaries after resetting the cluster]' \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_status {
  _arguments \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_upgrade {
  _arguments \
    '(-f --force)'{-f,--force}'[force start upgrade process]' \
    '--upgrade-machine-deployments[upgrade MachineDeployments objects]' \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

function _kubeone_version {
  _arguments \
    '(-c --credentials)'{-c,--credentials}'[File to source credentials and secrets from]:' \
    '(-d --debug)'{-d,--debug}'[debug output with stacktrace]' \
    '(-m --manifest)'{-m,--manifest}'[Path to the KubeOne config]:' \
    '(-t --tfjson)'{-t,--tfjson}'[Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, `terraform output -json` is executed in this path]:' \
    '(-v --verbose)'{-v,--verbose}'[verbose output]'
}

