#compdef arename

# Written by Frank Terbeck <ft@bewatermyfriend.org>.
#
# Distributed with arename <http://ft.bewatermyfriend.org/comp/arename.html>,
# under the same terms as arename itself (2-clause BSD); See the LICENCE file
# which is included in the arename distribution.

local arguments
local -a supported_extensions

supported_extensions=( 'mp3' 'ogg' 'flac' )

function _arename_files() {
    _path_files -g "(#i)*.(${(j:|:)supported_extensions})" -g "*(-/)"
}

function _arename_profiles() {
    local expl
    local -a already

    compset -P '*,'
    already=(${(s<,>)IPREFIX})
    _wanted list expl 'profile(s)' compadd -S, -F already -q ${expl} \
        -- ${(f)"$(arename --list-profiles)"}
}

arguments=(
    '--compare-versions[compare versions of script and module]:'
    '(--copy -c)'{--copy,-c}'[copy files, rather than rename]'
    '(--debug -D)'{--debug,-D}'[enable debugging output]'
    '(--disable-hooks -H)'{--disable-hooks,-H}'[disable all hooks]'
    '(--disable-profiles -N)'{--disable-profiles,-N}'[disable all profiles]'
    '(--dryrun -d)'{--dryrun,-d}'[go into dry-run mode]'
    '--enable-hooks[enable hooks, if they are disabled in the configuration]'
    '(--force -f)'{--force,-f}'[overwrite file(s) if needed]'
    '(--help -h)'{--help,-h}'[display help information]:'
    '(--list-cfg -L)'{--list-cfg,-L}'[list current configuration]:'
    '(--list-profiles -S)'{--list-profiles,-S}'[list all profiles in active configuration]:'
    '(--verbose -v --quiet -q)'{--quiet,-q}'[enable quiet output]'
    '(--read-local -l)'{--read-local,-l}'[read local config file]'
    '(--stdin -s)'{--stdin,-s}'[read filenames from stdin]'
    '(--verbose -v --uber-quiet -Q)'{--uber-quiet,-Q}'[do not display skips in quiet mode]'
    '(--quiet -q --uber-quiet -Q --verbose -v)'{--verbose,-v}'[enable verbose output]'
    '(--version -V)'{--version,-v}'[display version infomation]:'

    '--rc[read a file instead of ~/.arenamerc]:config file:_files'
    '--post-rc[read a file in addition to ~/.arenamerc]:config file:_files'

    '(--prefix -p)'{--prefix,-p}'[define a directory prefix for destination file(s)]:directory prefix:_path_files -g '\''*(-/)'\'
    '(--profile -P)'{--profile,-P}'[force the use of certain profile(s)]:profile(s):_arename_profiles'

    '(--compilation-template -T)'{--compilation-template,-T}'[define a compilation template]:compilation template:'
    '(--template -t)'{--template,-t}'[define a generic template]:template:'

    '*'{--userset,-u}'[set a user variable]:user variable (format var=value):'

    '*:audio files:_arename_files'
)

_arguments -s $arguments
