# Bash/ZSH completion for t2fm

_t2fm() {
    #compdef t2fm
    if type compdef &> /dev/null; then
        local opts=(
            '(-r -R -F)'{-i,-i}'[Interface to capture traffic from]:interface:_net_interfaces'
            '(-i -R -F)'{-r,-r}'[PCAP file to analyse]:file:_files'
            '(-i -r -F)'{-R,-R}'[List of PCAP files to analyse]:file:_files'
            '(-i -r -R)'{-F,-F}'[Flow file to analyse]:file:_files'
            '-b[Configure and build Tranalyzer2 and the plugins]'
            '-f[hashfactor]:Multiplication factor for hash table (int):'
            '-o[folder]:Output folder:'
            '-w[prefix]:Output prefix:'
            '-t[title]:Set the report title:'
            '-a[author]:Set the report author:'
            '-c[color]:Set the chart color:'
            '-L[Do not use logarithmic scale for axis]'
            '-n[num]:Compute to num statistics for tables (int):'
            '-m[num]:Compute to num statistics for charts (int):'
            '(- 1 *)'{-h,--help}'[Show help options and exit]'
        )
        _arguments -s -S "${opts[@]}"
    else # BASH
        local cur prev words cword
        _init_completion || return
        case $prev in
            -i|--iface)
                # active interfaces only
                _available_interfaces -a
                return
                ;;
            -r|--pcap|-R|--caplist|-w|--output-prefix|-F|--flow-file)
                _filedir
                return
                ;;
            -o|--output-folder)
                _filedir -d
                return
                ;;
            #-p)
            #    _filedir -d
            #    return
            #    ;;
        esac
        local args=(
            -i --iface -r --pcap -R --caplist -F --flow-file -b --build
            -f --hash-factor -o --output-folder -w --output-prefix -t --title
            -a --author -c --color -L --no-log-axis -n --table-n -m --chart-n
            -H --raw-numbers -HH --raw-and-hrnum -A --open-pdf -h -? --help)
        COMPREPLY=($(compgen -W "${args[*]}" -- "$cur"))
    fi
}

if type compdef &> /dev/null; then
    compdef _t2fm t2fm
else
    complete -F _t2fm t2fm
fi
