_gnocchi()
{
  local cur prev words
  COMPREPLY=()
  _get_comp_words_by_ref -n : cur prev words

  # Command data:
  cmds='aggregates archive-policy archive-policy-rule benchmark capabilities complete help measures metric resource resource-type server status'
  cmds_aggregates='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending --resource-type --start --stop --granularity --needed-overlap --groupby --fill --use-history'
  cmds_archive_policy='create delete list show update'
  cmds_archive_policy_rule='create delete list show update'
  cmds_archive_policy_rule_create='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty -a --archive-policy-name -m --metric-pattern'
  cmds_archive_policy_rule_delete='-h --help'
  cmds_archive_policy_rule_list='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending'
  cmds_archive_policy_rule_show='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty'
  cmds_archive_policy_rule_update='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty -n --name'
  cmds_archive_policy_create='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty -d --definition -b --back-window -m --aggregation-method'
  cmds_archive_policy_delete='-h --help'
  cmds_archive_policy_list='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending'
  cmds_archive_policy_show='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty'
  cmds_archive_policy_update='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty -d --definition'
  cmds_benchmark='measures metric'
  cmds_benchmark_measures='add show'
  cmds_benchmark_measures_add='-h --help --resource-id -r -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --workers -w --count -n --batch -b --timestamp-start -s --timestamp-end -e --wait'
  cmds_benchmark_measures_show='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending --utc --resource-id -r --aggregation --start --stop --granularity --refresh --resample --workers -w --count -n'
  cmds_benchmark_metric='create show'
  cmds_benchmark_metric_create='-h --help --resource-id -r -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --archive-policy-name -a --workers -w --count -n --keep -k'
  cmds_benchmark_metric_show='-h --help --resource-id -r -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --workers -w --count -n'
  cmds_capabilities='list'
  cmds_capabilities_list='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty'
  cmds_complete='-h --help --name --shell'
  cmds_help='-h --help'
  cmds_measures='add aggregation batch-metrics batch-resources-metrics show'
  cmds_measures_add='-h --help --resource-id -r -m --measure'
  cmds_measures_aggregation='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending --utc -m --metric --aggregation --reaggregation --start --stop --granularity --needed-overlap --query --resource-type --groupby --refresh --resample --fill'
  cmds_measures_batch_metrics='-h --help'
  cmds_measures_batch_resources_metrics='-h --help --create-metrics'
  cmds_measures_show='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending --utc --resource-id -r --aggregation --start --stop --granularity --refresh --resample'
  cmds_metric='create delete list show'
  cmds_metric_create='-h --help --resource-id -r -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --archive-policy-name -a --unit -u'
  cmds_metric_delete='-h --help --resource-id -r'
  cmds_metric_list='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending --limit --marker --sort'
  cmds_metric_show='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --resource-id -r'
  cmds_resource='batch create delete history list search show update'
  cmds_resource_type='create delete list show update'
  cmds_resource_type_create='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty -a --attribute'
  cmds_resource_type_delete='-h --help'
  cmds_resource_type_list='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending'
  cmds_resource_type_show='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty'
  cmds_resource_type_update='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty -a --attribute -r --remove-attribute'
  cmds_resource_batch='delete'
  cmds_resource_batch_delete='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --type -t'
  cmds_resource_create='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --type -t -a --attribute -m --add-metric -n --create-metric'
  cmds_resource_delete='-h --help'
  cmds_resource_history='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending --details --limit --marker --sort --type -t'
  cmds_resource_list='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending --details --history --limit --marker --sort --type -t'
  cmds_resource_search='-h --help -f --format -c --column --quote --noindent --max-width --fit-width --print-empty --sort-column --sort-ascending --sort-descending --details --history --limit --marker --sort --type -t'
  cmds_resource_show='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --type -t'
  cmds_resource_update='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty --type -t -a --attribute -m --add-metric -n --create-metric -d --delete-metric'
  cmds_server='version'
  cmds_server_version='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty'
  cmds_status='-h --help -f --format -c --column --noindent --variable --prefix --max-width --fit-width --print-empty'

  dash=-
  underscore=_
  cmd=""
  words[0]=""
  completed="${cmds}"
  for var in "${words[@]:1}"
  do
    if [[ ${var} == -* ]] ; then
      break
    fi
    if [ -z "${cmd}" ] ; then
      proposed="${var}"
    else
      proposed="${cmd}_${var}"
    fi
    local i="cmds_${proposed}"
    i=${i//$dash/$underscore}
    local comp="${!i}"
    if [ -z "${comp}" ] ; then
      break
    fi
    if [[ ${comp} == -* ]] ; then
      if [[ ${cur} != -* ]] ; then
        completed=""
        break
      fi
    fi
    cmd="${proposed}"
    completed="${comp}"
  done

  if [ -z "${completed}" ] ; then
    COMPREPLY=( $( compgen -f -- "$cur" ) $( compgen -d -- "$cur" ) )
  else
    COMPREPLY=( $(compgen -W "${completed}" -- ${cur}) )
  fi
  return 0
}
complete -F _gnocchi gnocchi
