#compdef _charm charm


function _charm {
  local -a commands

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

  case $state in
  cmnds)
    commands=(
      "backup-keys:Backup your Charm account keys"
      "completion:Generate shell completion"
      "crypt:Use Charm encryption."
      "fs:Use the Charm file system."
      "help:Help about any command"
      "id:Print your Charm ID"
      "import-keys:Import previously backed up Charm account keys."
      "jwt:Print a JWT"
      "keys:Browse or print linked SSH keys"
      "kv:Use the Charm key value store."
      "link:Link multiple machines to your Charm account"
      "name:Username stuff"
      "serve:Start a self-hosted Charm Cloud server."
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  backup-keys)
    _charm_backup-keys
    ;;
  completion)
    _charm_completion
    ;;
  crypt)
    _charm_crypt
    ;;
  fs)
    _charm_fs
    ;;
  help)
    _charm_help
    ;;
  id)
    _charm_id
    ;;
  import-keys)
    _charm_import-keys
    ;;
  jwt)
    _charm_jwt
    ;;
  keys)
    _charm_keys
    ;;
  kv)
    _charm_kv
    ;;
  link)
    _charm_link
    ;;
  name)
    _charm_name
    ;;
  serve)
    _charm_serve
    ;;
  esac
}

function _charm_backup-keys {
  _arguments
}

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


function _charm_crypt {
  local -a commands

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

  case $state in
  cmnds)
    commands=(
      "decrypt:Decrypt stdin with your Charm account encryption key"
      "decrypt-lookup:Decrypt arg deterministically"
      "encrypt:Encrypt stdin with your Charm account encryption key"
      "encrypt-lookup:Encrypt arg deterministically"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  decrypt)
    _charm_crypt_decrypt
    ;;
  decrypt-lookup)
    _charm_crypt_decrypt-lookup
    ;;
  encrypt)
    _charm_crypt_encrypt
    ;;
  encrypt-lookup)
    _charm_crypt_encrypt-lookup
    ;;
  esac
}

function _charm_crypt_decrypt {
  _arguments
}

function _charm_crypt_decrypt-lookup {
  _arguments
}

function _charm_crypt_encrypt {
  _arguments
}

function _charm_crypt_encrypt-lookup {
  _arguments
}


function _charm_fs {
  local -a commands

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

  case $state in
  cmnds)
    commands=(
      "cat:Output the content of the file at path."
      "cp:Copy a file, preface source or destination with "charm:" to specify a remote path."
      "ls:List file or directory at path"
      "mv:Move a file, preface source or destination with "charm:" to specify a remote path."
      "rm:Remove file or directory at path"
      "tree:Print a file system tree from path."
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  cat)
    _charm_fs_cat
    ;;
  cp)
    _charm_fs_cp
    ;;
  ls)
    _charm_fs_ls
    ;;
  mv)
    _charm_fs_mv
    ;;
  rm)
    _charm_fs_rm
    ;;
  tree)
    _charm_fs_tree
    ;;
  esac
}

function _charm_fs_cat {
  _arguments
}

function _charm_fs_cp {
  _arguments \
    '(-r --recursive)'{-r,--recursive}'[copy directories recursively]'
}

function _charm_fs_ls {
  _arguments
}

function _charm_fs_mv {
  _arguments \
    '(-r --recursive)'{-r,--recursive}'[move directories recursively]'
}

function _charm_fs_rm {
  _arguments
}

function _charm_fs_tree {
  _arguments
}

function _charm_help {
  _arguments
}

function _charm_id {
  _arguments
}

function _charm_import-keys {
  _arguments \
    '(-f --force-overwrite)'{-f,--force-overwrite}'[overwrite if keys exist; don’t prompt for input]'
}

function _charm_jwt {
  _arguments
}

function _charm_keys {
  _arguments \
    '(-r --randomart)'{-r,--randomart}'[print SSH 5.1 randomart for each key (the Drunken Bishop algorithm)]' \
    '(-s --simple)'{-s,--simple}'[simple, non-interactive output (good for scripts)]'
}


function _charm_kv {
  local -a commands

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

  case $state in
  cmnds)
    commands=(
      "delete:Delete a key with an optional @ db."
      "get:Get a value for a key with an optional @ db."
      "list:List all key value pairs with an optional @ db."
      "reset:Delete local db and pull down fresh copy from Charm Cloud."
      "set:Set a value for a key with an optional @ db."
      "sync:Sync local db with latest Charm Cloud db."
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  delete)
    _charm_kv_delete
    ;;
  get)
    _charm_kv_get
    ;;
  list)
    _charm_kv_list
    ;;
  reset)
    _charm_kv_reset
    ;;
  set)
    _charm_kv_set
    ;;
  sync)
    _charm_kv_sync
    ;;
  esac
}

function _charm_kv_delete {
  _arguments
}

function _charm_kv_get {
  _arguments \
    '(-b --show-binary)'{-b,--show-binary}'[print binary values]'
}

function _charm_kv_list {
  _arguments \
    '(-d --delimiter)'{-d,--delimiter}'[delimiter to separate keys and values]:' \
    '(-k --keys-only)'{-k,--keys-only}'[only print keys and don'\''t fetch values from the db]' \
    '(-r --reverse)'{-r,--reverse}'[list in reverse lexicographic order]' \
    '(-b --show-binary)'{-b,--show-binary}'[print binary values]' \
    '(-v --values-only)'{-v,--values-only}'[only print values]'
}

function _charm_kv_reset {
  _arguments
}

function _charm_kv_set {
  _arguments
}

function _charm_kv_sync {
  _arguments
}

function _charm_link {
  _arguments
}

function _charm_name {
  _arguments
}


function _charm_serve {
  local -a commands

  _arguments -C \
    '--data-dir[Directory to store SQLite db, SSH keys and file data]:' \
    '--health-port[Health port to listen on]:' \
    '--http-port[HTTP port to listen on]:' \
    '--ssh-port[SSH port to listen on]:' \
    '--stats-port[Stats port to listen on]:' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  esac
}

