#-*- mode: shell-script; -*-

# haxe(1) bash completion specification.
# Put in the public domain 2008 by Jens Peter Secher.

_haxe()
{
    local cur prev options    
    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}
    options='-cp -js -as3 -swf -swf-version -swf-header -swf-lib \
             -neko -x -xml -main -lib -D -resource -exclude -v \
             -debug -prompt -cmd --flash-strict --override --no-traces \
             --flash-use-stage --neko-source --gen-hx-classes --next \
             --altfmt --auto-xml --display --no-output --times -help \
             --help'
    case $prev in
	-cp|-as3)
            COMPREPLY=( $( compgen -d -- ${cur} ) )
            ;;
	-js)
            COMPREPLY=( $( compgen -o filenames -G "${cur}*.js" ) )
            ;;
	-swf|-swf-lib)
            COMPREPLY=( $( compgen -o filenames -G "${cur}*.swf" ) )
            ;;
	-neko|-x)
            COMPREPLY=( $( compgen -o filenames -G "${cur}*.n" ) )
            ;;
	-xml)
            COMPREPLY=( $( compgen -o filenames -G "${cur}*.xml" ) )
            ;;
	-exclude)
            COMPREPLY=( $( compgen -o filenames -G "${cur}*.hx" ) )
            ;;
        -swf-version)
	    local swf_versions='6 7 8 9'
	    COMPREPLY=( $( compgen -W "${swf_versions}" -- ${cur} ) )
	    ;;
        -swf-header)
            ## An improvement here would be to restrict to n:n:n:c.
            ;;
        -main)
            ## An improvement here would be to find class Xxx in *.hx
            ## files, alternatively just Xxx.hx.
            ;;
        -lib)
            if haxelib list 2>&1 > /dev/null; then
                local libraries=`haxelib list | sed 's/:.*//g'`
                COMPREPLY=( $( compgen -W "${libraries}" -- ${cur} ) )
            fi
            ;;
        -D)
            ## An improvement here would be to grep in hx files after #if xxx.
            ;;
        -cmd)
            ## Nothing.
            ;;
        -resource)
            ## Nothing.
	    ;;
	*)
	    COMPREPLY=( $( compgen -W "${options}" -- ${cur} ) )
	    ;;
    esac
    return 0
}
complete -F _haxe -o filenames haxe
