zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: "Jesper Nygårds" <jesper.nygards@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Putting options after tasks
Date: Wed, 14 Mar 2012 19:30:16 +0100	[thread overview]
Message-ID: <CAHYJk3QfcC027ardhVWGOp=Ks=C77_RqwP8HTDgCCcivqJ6GZg@mail.gmail.com> (raw)
In-Reply-To: <CABZhJg9sya0JmRYG+2OYw6nb=eX_ZBj37fFXn_Jit1fTK8zrDw@mail.gmail.com>

2012/3/14 Jesper Nygårds <jesper.nygards@gmail.com>:
> 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?

Replace :: with : and it will "work", however there are some other
problems with the code you wrote. You modify the $commands array
without making it local, you also forget to local a few other things.
The following seems to work fine (i also put it in an autoloaded
_gradle file in $fpath):


#compdef gradle

local ret=1 state state_descr line
local curcontext="$curcontext"
local -A opt_args
local -a commands

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

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

return ret

-- 
Mikael Magnusson


  parent reply	other threads:[~2012-03-14 18:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-14  8:53 Jesper Nygårds
2012-03-14 17:19 ` Bart Schaefer
2012-03-15  7:31   ` Jesper Nygårds
2012-03-14 18:30 ` Mikael Magnusson [this message]
2012-03-15  7:33   ` Jesper Nygårds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHYJk3QfcC027ardhVWGOp=Ks=C77_RqwP8HTDgCCcivqJ6GZg@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=jesper.nygards@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).