#compdef isi hdfs

# Copyright C 2008-2011 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_hdfs] )) ||
_isi_hdfs() {
    local longer=0
    if [ "$CURRENT" -gt 2 ]; then
        local match=0
        for sub_command in racks krb5 ; do
            if [ "${words[2]}" = "$sub_command" ]; then
                match=1 ; break
            fi
        done
        if [ "$match" -ne 1 ]; then
            longer=1
        fi
    fi
    if [ "$CURRENT" -eq 2 -o "$longer" -eq 1 ]; then
        if [ "$CURRENT" -eq 2 ]; then
            _tags values && {compadd $@ krb5 racks}
        fi
        _arguments \
            '--force-version=[Version of Hadoop client software]:hadoop_version:_isi_list_hdfs_objs -H' \
            '--log-level=[Logging verbosity]:log_level:_isi_list_hdfs_objs -l' \
            '--root-path=[Set the HDFS-exposed root path]' \
            '--block-size=[Set the block size used for reads]' \
            '--num-threads=[Set the number of worker threads used by the Hadoop daemon]' \
            '--hadoop-security=[Set authentication security mode]:hadoop_security:_isi_list_hdfs_objs -S' \
            '--help[Print usage help and exit]' 

    else
        local cmd=${words[2]}
        (( CURRENT-- ))
        shift words
        if [[ $cmd == racks ]]; then
            curcontext="${curcontext%:*:*}:isi-hdfs-racks:"
            _isi_hdfs_racks
        elif [[ $cmd == krb5 ]]; then
            curcontext="${curcontext%:*:*}:isi-hdfs-krb5:"
            _isi_hdfs_krb5
        fi
    fi
}

(( $+functions[_isi_list_hdfs_objs] )) ||
_isi_list_hdfs_objs() {
    _tags values && { compadd $1 $2 `/usr/local/share/zsh/site-functions/list-hdfs-objs $3` }
}

(( $+functions[_isi_list_net_objs] )) ||
_isi_list_net_objs() {
    _tags values && { compadd $1 $2 `/usr/local/share/zsh/site-functions/list-net-objs $3` }
}

(( $+functions[_isi_hdfs_racks] )) ||
_isi_hdfs_racks() {
    if (( CURRENT == 2 )); then
        _tags values && {compadd $@ create delete list modify view }
    else
        local cmd=${words[2]}
        (( CURRENT-- ))
        shift words
        if [[ $cmd == create ]]; then
            curcontext="${curcontext%:*:*}:isi-hdfs-racks-create:"
            _isi_hdfs_racks_create
        elif [[ $cmd == delete ]]; then
            curcontext="${curcontext%:*:*}:isi-hdfs-racks-delete:"
            _isi_hdfs_racks_delete
        elif [[ $cmd == list ]]; then
            curcontext="${curcontext%:*:*}:isi-hdfs-racks-list:"
            _isi_hdfs_racks_list
        elif [[ $cmd == modify ]]; then
            curcontext="${curcontext%:*:*}:isi-hdfs-racks-modify:"
            _isi_hdfs_racks_modify
        elif [[ $cmd == view ]]; then
            curcontext="${curcontext%:*:*}:isi-hdfs-racks-view:"
            _isi_hdfs_racks_view
        fi
    fi
}

(( $+functions[_isi_hdfs_racks_create] )) ||
_isi_hdfs_racks_create() {
    _arguments \
        '--name=[The name of the rack, in the form /example/name]:rack_name:_isi_list_hdfs_objs -n' \
        "--add-client-ip=[Assign an individual client IP to this rack (in 'w.x.y.z' form)]" \
        "--add-client-range=[Assign a range of client IPs to this rack ('a.b.c.d-w.x.y.z')]" \
        "--add-ip-pool=[Assign an ip pool to this rack]:pool_name:_isi_list_net_objs -pf" \
        '--help[Print usage help and exit]'
}

(( $+functions[_isi_hdfs_racks_delete] )) ||
_isi_hdfs_racks_delete() {
    _arguments \
        '--name=[The name of the rack, in the form /example/name]:rack_name:_isi_list_hdfs_objs -n' \
        '--help[Print usage help and exit]'
}

(( $+functions[_isi_hdfs_racks_list] )) ||
_isi_hdfs_racks_list() {
    _arguments \
        '--verbose[List verbosely]' \
        '--help[Print usage help and exit]'
}

(( $+functions[_isi_hdfs_racks_modify] )) ||
_isi_hdfs_racks_modify() {
    _arguments \
        '--name=[The name of the rack, in the form /example/name]:rack_name:_isi_list_hdfs_objs -n' \
        '--new-name=[New name for the rack; must be unique]' \
        "--add-client-ip=[Assign an individual client IP to this rack (in 'w.x.y.z' form)]" \
        "--add-client-range=[Assign a range of client IPs to this rack ('a.b.c.d-w.x.y.z')]" \
        "--remove-client-ip=[Remove an individual client IP from this rack (in 'w.x.y.z' form)]" \
        "--remove-client-range=[Remove a range of client IPs from this rack ('a.b.c.d-w.x.y.z')]" \
        "--add-ip-pool=[Assign an ip pool to this rack]:pool_name:_isi_list_net_objs -pf" \
        "--remove-ip-pool=[Remove an ip pool from this rack]:pool_name:_isi_list_net_objs -pf" \
        '--help[Print usage help and exit]'
}

(( $+functions[_isi_hdfs_racks_view] )) ||
_isi_hdfs_racks_view() {
    _arguments \
        '--name=[The name of the rack, in the form /example/name]:rack_name:_isi_list_hdfs_objs -n' \
        '--help[Print usage help and exit]'
}

(( $+functions[_isi_hdfs_krb5] )) ||
_isi_hdfs_krb5() {
    _arguments \
        '--kerb-instance=[Instance name used in hdfs service principal]' \
        '--keytab=[Set the hdfs keytab file path]' \
        '--help[Print usage help and exit]'
}
