Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Putting options after tasks



I am trying to write a completion function for gradle, and face some
problems regarding the order of options and tasks.

Below I have simplified my approach as much as possible, in order to
explain my problem clearly. The basis for this is originally the
gradle completion from oh-my-zsh.

gradle can take any number of options (long options starting with
"--") and tasks (with no prefix). In my example below, I have boiled
this down to two options ("--info" and "--stacktrace"), and two tasks
("build" and "clean").

These options and tasks can come in any order, so the following
command lines would all be valid:
gradle clean build
gradle --info clean build --stacktrace
gradle --stacktrace --info clean build
etc

My problem is this: the completion below works fine and completes both
options and tasks, but once I have at least one task on the command
line, it no longer completes for options. So, for example, if I have
"gradle build --i" and press <tab>, I get no suggestions, whereas
"gradle bu<tab>" gives "gradle build", and "gradle --i<tab>" gives
"gradle --info".

What do I have to do to make it possible to complete options after tasks?

_gradle() {
    local ret=1 state
    local curcontext="$curcontext"

    _arguments -C \
        '--info[Log at the info level]' \
        '--stacktrace[Display stacktrace on error]' \
        '*::command:->command' \
        && ret=0

    if [[ -n $state ]]; then
        commands=( "clean:Clean the project" "build:Build the project" )
        _describe -t commands 'gradle commands' commands && ret=0
    fi

    return $ret
}

compdef _gradle gradle



Messages sorted by: Reverse Date, Date, Thread, Author