zsh-users
 help / color / mirror / code / Atom feed
* Completion using state-machine
@ 2008-01-31 10:28 Marco Lombardi
  2008-01-31 16:26 ` Clint Adams
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Lombardi @ 2008-01-31 10:28 UTC (permalink / raw)
  To: zsh-users

Dear all,

I need to write completion code for a complex program that can accept
different kind of arguments depending on what is already present on
the command line.  To make an short example, consider the following
specifications

{-v,--verbose} - increase verbosity of messages, can be used up to three times
{-s,--simple} - simple flag, can be used only once in the whole line
{-p,--path}=PATH - specify a directory (e.g., _files -/) for following commands
{--parameter}=PAR - set some specific parameter, can be used once for
a specified path

Note that while --simple can be used only once in the whole line,
--parameter=PAR can be used many times for differeht --path's.  For
example, the following command line is acceptable

command -vv --parameter=1 -p /tmp --parameter=2 --simple
--path=${HOME} --parameter=3

To implement this I would be tempted to use _arguments with the ->
action, which in principle would let me implement a full
state-machine.  However, although I spent the last few days in trying
to understand how to use the possibilities offered by the -> and the
$state variable to do what I need to.  I would appreciate then a
simple code example to implement the example I just provided.

Many thanks,
Marco Lombardi


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Completion using state-machine
  2008-01-31 10:28 Completion using state-machine Marco Lombardi
@ 2008-01-31 16:26 ` Clint Adams
  2008-01-31 17:03   ` Marco Lombardi
  0 siblings, 1 reply; 3+ messages in thread
From: Clint Adams @ 2008-01-31 16:26 UTC (permalink / raw)
  To: Marco Lombardi; +Cc: zsh-users

On Thu, Jan 31, 2008 at 11:28:55AM +0100, Marco Lombardi wrote:
> {-v,--verbose} - increase verbosity of messages, can be used up to three times
> {-s,--simple} - simple flag, can be used only once in the whole line
> {-p,--path}=PATH - specify a directory (e.g., _files -/) for following commands
> {--parameter}=PAR - set some specific parameter, can be used once for
> a specified path

This probably doesn't answer your question, but if you're not strictly
concerned with option order nd context, you can avoid using a state
machine and just do something like

_arguments -s \
  \*{-v,--verbose}'[increase verbosity of messages]' \
  '(-s --simple)'{-s,--simple}'[simple flag]' \
  \*{-p,--path=}':directory for following commands:_directories' \
  '*--parameter=:parameter:(1 2 3)'


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Completion using state-machine
  2008-01-31 16:26 ` Clint Adams
@ 2008-01-31 17:03   ` Marco Lombardi
  0 siblings, 0 replies; 3+ messages in thread
From: Marco Lombardi @ 2008-01-31 17:03 UTC (permalink / raw)
  To: zsh-users

Hi,

many thanks for the answer, but unfortunately what I need cannot be
easily done as you suggest.  I am actually concerned about option
orders (two --parameter's options without a --path in between are not
acceptable); in addition, I want at most three --verbose options, no
more.

So I guess I really need to understand how to use the -> states.  Regards,

Marco

On Jan 31, 2008 5:26 PM, Clint Adams <clint@zsh.org> wrote:
> On Thu, Jan 31, 2008 at 11:28:55AM +0100, Marco Lombardi wrote:
> > {-v,--verbose} - increase verbosity of messages, can be used up to three times
> > {-s,--simple} - simple flag, can be used only once in the whole line
> > {-p,--path}=PATH - specify a directory (e.g., _files -/) for following commands
> > {--parameter}=PAR - set some specific parameter, can be used once for
> > a specified path
>
> This probably doesn't answer your question, but if you're not strictly
> concerned with option order nd context, you can avoid using a state
> machine and just do something like
>
> _arguments -s \
>   \*{-v,--verbose}'[increase verbosity of messages]' \
>   '(-s --simple)'{-s,--simple}'[simple flag]' \
>   \*{-p,--path=}':directory for following commands:_directories' \
>   '*--parameter=:parameter:(1 2 3)'
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-01-31 17:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-31 10:28 Completion using state-machine Marco Lombardi
2008-01-31 16:26 ` Clint Adams
2008-01-31 17:03   ` Marco Lombardi

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).