# gige-daemon completion                             -*- shell-script -*-

# Copyright 2018 The Imaging Source Europe GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


_tcam-gige-daemon () {

    local cur prev words cword
    _init_completion || return

    # if [[ -n $command ]]; then
    case $prev in
        start)
            COMPREPLY=( $( compgen -W "--no-fork" -- "$cur" ) )
            return 0
            ;;
    esac

    # complete using basic options
    COMPREPLY=( $( compgen -W '-h --help start stop list list-long' -- "$cur" ) )


    if [[ ${#COMPREPLY[@]} -ne 0 ]]; then
        # this removes any options from the list of completions that have
        # already been specified somewhere on the command line, as long as
        # these options can only be used once (in a word, "options", in
        # opposition to "tests" and "actions", as in the find(1) manpage).
        local -A onlyonce=( [start]=1 [stop]=1 [--help]=1 [-h]=1
                            [list]=1 [list-long]=1 [--no-fork]=1 )
        local j
        for i in "${words[@]}"; do
            [[ $i && ${onlyonce[$i]} ]] || continue
            for j in ${!COMPREPLY[@]}; do
                [[ ${COMPREPLY[j]} == $i ]] && unset 'COMPREPLY[j]'
            done
        done
    fi

    return 0
} &&
    complete -F _tcam-gige-daemon tcam-gige-daemon
