#compdef balena
#autoload

#GENERATED FILE DON'T MODIFY#

_balena() {
  typeset -A opt_args
  local context state line curcontext="$curcontext"

  # Valid top-level completions
  main_commands=( api-key app block build config deploy device device-type env fleet internal join leave local login logout organization os preload push release settings ssh-key support tag util version whoami )
  # Sub-completions
  api_key_cmds=( generate list revoke )
  app_cmds=( create )
  block_cmds=( create )
  config_cmds=( generate inject read reconfigure write )
  device_type_cmds=( list )
  device_cmds=( deactivate detect identify init list local-mode logs move note os-update pin public-url purge reboot register rename restart rm shutdown ssh start-service stop-service track-fleet tunnel )
  env_cmds=( list rename rm set )
  fleet_cmds=( create list pin purge rename restart rm track-latest )
  internal_cmds=( osinit )
  local_cmds=( configure flash )
  organization_cmds=( list )
  os_cmds=( build-config configure download initialize versions )
  release_cmds=( finalize invalidate list validate )
  ssh_key_cmds=( add list rm )
  tag_cmds=( list rm set )


  _arguments -C \
    '(- 1 *)--version[show version and exit]' \
    '(- 1 *)--help[show help options and exit]' \
    '1:first command:_balena_main_cmds' \
    '2:second command:_balena_sec_cmds' \
  && ret=0
}

(( $+functions[_balena_main_cmds] )) ||
_balena_main_cmds() {
  _describe -t main_commands 'command' main_commands "$@" && ret=0
}

(( $+functions[_balena_sec_cmds] )) ||
_balena_sec_cmds() {
  case $line[1] in
      "api-key")
        _describe -t api_key_cmds 'api-key_cmd' api_key_cmds "$@" && ret=0
      ;;
      "app")
        _describe -t app_cmds 'app_cmd' app_cmds "$@" && ret=0
      ;;
      "block")
        _describe -t block_cmds 'block_cmd' block_cmds "$@" && ret=0
      ;;
      "config")
        _describe -t config_cmds 'config_cmd' config_cmds "$@" && ret=0
      ;;
      "device-type")
        _describe -t device_type_cmds 'device-type_cmd' device_type_cmds "$@" && ret=0
      ;;
      "device")
        _describe -t device_cmds 'device_cmd' device_cmds "$@" && ret=0
      ;;
      "env")
        _describe -t env_cmds 'env_cmd' env_cmds "$@" && ret=0
      ;;
      "fleet")
        _describe -t fleet_cmds 'fleet_cmd' fleet_cmds "$@" && ret=0
      ;;
      "internal")
        _describe -t internal_cmds 'internal_cmd' internal_cmds "$@" && ret=0
      ;;
      "local")
        _describe -t local_cmds 'local_cmd' local_cmds "$@" && ret=0
      ;;
      "organization")
        _describe -t organization_cmds 'organization_cmd' organization_cmds "$@" && ret=0
      ;;
      "os")
        _describe -t os_cmds 'os_cmd' os_cmds "$@" && ret=0
      ;;
      "release")
        _describe -t release_cmds 'release_cmd' release_cmds "$@" && ret=0
      ;;
      "ssh-key")
        _describe -t ssh_key_cmds 'ssh-key_cmd' ssh_key_cmds "$@" && ret=0
      ;;
      "tag")
        _describe -t tag_cmds 'tag_cmd' tag_cmds "$@" && ret=0
      ;;

  esac
}

_balena "$@"
