#compdef isi ndmp

# Copyright C 2002-2007 by Isilon Systems, Inc. All rights not expressly
# granted herein are reserved.
# Created in the United States of America.
# 
# This digital media is protected by U.S. and international copyright and
# intellectual property laws. Unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of Isilon Systems,
# Inc.
# 
# Except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of Isilon
# Systems. 
#  
# Isilon and Isilon Systems are registered trademarks of Isilon Systems,
# Inc.  Legion is a trademark of Isilon Systems, Inc.  All other
# trademarks and registered trademarks are the property of their
# respective holders.

(( $+functions[__isi_ndmp] )) ||
_isi_ndmp() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ list settings user kill probe extensions dumpdates}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == list ]]; then
      curcontext="${curcontext%:*:*}:isi-ndmp-list:"
      _isi_ndmp_list
    elif [[ $cmd == settings ]]; then
      curcontext="${curcontext%:*:*}:isi-ndmp-settings:"
      _isi_ndmp_settings
    elif [[ $cmd == user ]]; then
      curcontext="${curcontext%:*:*}:isi-ndmp-user:"
      _isi_ndmp_user
    elif [[ $cmd == kill ]]; then
      curcontext="${curcontext%:*:*}:isi-ndmp-kill:"
      _isi_ndmp_kill
    elif [[ $cmd == probe ]]; then
      curcontext="${curcontext%:*:*}:isi-ndmp-probe:"
      _isi_ndmp_probe
    elif [[ $cmd == extensions ]]; then
      curcontext="${curcontext%:*:*}:isi-ndmp-extensions:"
      _isi_ndmp_extensions
    elif [[ $cmd == dumpdates ]]; then
      curcontext="${curcontext%:*:*}:isi-ndmp-dumpdates:"
      _isi_ndmp_dumpdates
    else
      _message "unknown isi ndmp command: $words[1]"
    fi
  fi
}

(( $+functions[_isi_ndmp_session_list] )) ||
_isi_ndmp_session_list() {
     _tags values && { compadd $@ `isi ndmp list | awk '{ if (FNR > 2) print $1}'` }
}

(( $+functions[_isi_ndmp_list] )) ||
_isi_ndmp_list() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--session=[id of session to display]:session_id:_isi_ndmp_session_list' \
    '--verbose[Show device path information]' \
    '--node=[id of node for which to display sessions]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_settings] )) ||
_isi_ndmp_settings() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ list set variables}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == list ]]; then
      _isi_ndmp_settings_list
    elif [[ $cmd == set ]]; then
      _isi_ndmp_settings_set
    elif [[ $cmd == variables ]]; then
      _isi_ndmp_settings_variables
    else
      _message "unknown isi ndmp command: $words[1]"
    fi
  fi
}

(( $+functions[_isi_ndmp_settings_list] )) ||
_isi_ndmp_settings_list() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--name=[setting name to list]:set_name:_isi_ndmp_settings_set_name_list' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_settings_set_name_list] )) ||
_isi_ndmp_settings_set_name_list() {
    _tags values && { compadd port dma }
}

(( $+functions[_isi_ndmp_settings_set_value_list] )) ||
_isi_ndmp_settings_set_value_list() {
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == --name=dma ]]; then
        _tags values && { compadd generic symantec emc tivoli bakbone commvault atempo symantec-netbackup symantec-backupexec}
    fi
    if [[ $cmd == --name=port ]]; then
        _tags values && { compadd 10000 }
    fi
}

(( $+functions[_isi_ndmp_settings_set] )) ||
_isi_ndmp_settings_set() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--name=[setting name to set]:set_name:_isi_ndmp_settings_set_name_list' \
    '--value=[value for this setting]:set_value:_isi_ndmp_settings_set_value_list' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_settings_variables] )) ||
_isi_ndmp_settings_variables() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ list create modify delete}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == list ]]; then
      _isi_ndmp_settings_variables_list
    elif [[ $cmd == create ]]; then
      _isi_ndmp_settings_variables_create
    elif [[ $cmd == modify ]]; then
      _isi_ndmp_settings_variables_modify
    elif [[ $cmd == delete ]]; then
      _isi_ndmp_settings_variables_delete
    else
      _message "unknown isi ndmp command: $words[1]"
    fi
  fi
}

(( $+functions[_isi_ndmp_settings_variables_list] )) ||
_isi_ndmp_settings_variables_list() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--path=[backup path]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_settings_variables_create] )) ||
_isi_ndmp_settings_variables_create() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--path=[backup path]' \
    '--name=[name of the environment variable]' \
    '--value=[value of the environment variable]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_settings_variables_modify] )) ||
_isi_ndmp_settings_variables_modify() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--path=[backup path]' \
    '--name=[name of the environment variable]' \
    '--value=[value of the environment variable]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_settings_variables_delete] )) ||
_isi_ndmp_settings_variables_delete() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--path=[backup path]' \
    '--name=[name of the environment variable]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_user] )) ||
_isi_ndmp_user() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ list create delete modify }
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == list ]]; then
      _isi_ndmp_user_list_cmd
    elif [[ $cmd == create ]]; then
      _isi_ndmp_user_create
    elif [[ $cmd == delete ]]; then
      _isi_ndmp_user_delete
    elif [[ $cmd == modify ]]; then
      _isi_ndmp_user_modify
    else
      _message "unknown isi ndmp command: $words[1]"
    fi
  fi
}

(( $+functions[_isi_ndmp_user_list_cmd] )) ||
_isi_ndmp_user_list_cmd() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--name=[user name to list]:set_name:_isi_ndmp_user_list' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_user_create] )) ||
_isi_ndmp_user_create() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--name=[name of user to create]' \
    '--password=[password]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_user_list] )) ||
_isi_ndmp_user_list() {
     _tags values && { compadd $@ `isi ndmp user list | awk '{ if (FNR > 2) print $1 }'` }
}

(( $+functions[_isi_ndmp_user_modify] )) ||
_isi_ndmp_user_modify() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--name=[name of user to modify]:set_name:_isi_ndmp_user_list' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_user_delete] )) ||
_isi_ndmp_user_delete() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--name=[name of user to delete]:set_name:_isi_ndmp_user_list' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_kill] )) ||
_isi_ndmp_kill() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--session=[id of session to terminate]:session_id:_isi_ndmp_session_list' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_probe] )) ||
_isi_ndmp_probe() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--session=[id of session to probe]:session_id:_isi_ndmp_session_list' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_extensions] )) ||
_isi_ndmp_extensions() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ contexts settings}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == contexts ]]; then
      _isi_ndmp_extensions_contexts
    elif [[ $cmd == settings ]]; then
      _isi_ndmp_extensions_settings
    else
      _message "unknown isi ndmp command: $words[1]"
    fi
  fi
}

(( $+functions[_isi_ndmp_extensions_contexts] )) ||
_isi_ndmp_extensions_contexts() {
 if (( CURRENT == 2 )); then
    _tags values && { compadd $@ list view delete }
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == list ]]; then
      _isi_ndmp_extensions_contexts_list
    elif [[ $cmd == view ]]; then
      _isi_ndmp_extensions_contexts_view
    elif [[ $cmd == delete ]]; then
      _isi_ndmp_extensions_contexts_delete
    else
      _message "unknown isi ndmp command: $words[1]"
    fi
  fi
}

(( $+functions[_isi_ndmp_extensions_contexts_list] )) ||
_isi_ndmp_extensions_contexts_list() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--id=[context_id]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_extensions_contexts_view] )) ||
_isi_ndmp_extensions_contexts_view() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--id=[context_id]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_extensions_contexts_delete] )) ||
_isi_ndmp_extensions_contexts_delete() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--id=[context_id]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_extensions_settings] )) ||
_isi_ndmp_extensions_settings() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ view modify}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == view ]]; then
      _isi_ndmp_extensions_settings_view
    elif [[ $cmd == modify ]]; then
      _isi_ndmp_extensions_settings_modify
    else
      _message "unknown isi ndmp command: $words[1]"
    fi
  fi
}

(( $+functions[_isi_ndmp_extensions_settings_view] )) ||
_isi_ndmp_extensions_settings_view() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_extensions_settings_modify] )) ||
_isi_ndmp_extensions_settings_modify() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--bre_max_contexts=[bre_max_contexts between 1 and 1024]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_dumpdates] )) ||
_isi_ndmp_dumpdates() {
  if (( CURRENT == 2 )); then
    _tags values && { compadd $@ list delete }
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == list ]]; then
      _isi_ndmp_dumpdates_list
    elif [[ $cmd == delete ]]; then
      _isi_ndmp_dumpdates_delete
    else
      _message "unknown isi ndmp command: $words[1]"
    fi
  fi
}

(( $+functions[_isi_ndmp_dumpdates_list] )) ||
_isi_ndmp_dumpdates_list() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_ndmp_dumpdates_delete] )) ||
_isi_ndmp_dumpdates_delete() {
  _tags values && { compadd $@ --help }
  _arguments \
    '--path=[backup path]'\
    '--level=[number]'\
    '--help[Print usage help and exit]'
}

