zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: zparseopts help
Date: Fri, 23 Jan 2015 09:15:11 -0800	[thread overview]
Message-ID: <150123091511.ZM1667@torch.brasslantern.com> (raw)
In-Reply-To: <CADjGqHt4bv3QGOCne_yktMVbeu+TbC+jj_q8wVvHO-9TQt_4ww@mail.gmail.com>

On Jan 23, 10:39am, TJ Luoma wrote:
}
} I took a look through the `man` entry, but I don't know what it is about
} my brain, but I can read and re-read man pages and still fail to understand
} what it is saying. I do much better with examples.

Not uncommon ... if we could find some volunteers to write more examples
for the manual, that would be nice.

} zparseopts -D -E -A MyVariableNameHere -- a b -orange -grape -apple
} 
} Questions:
} 
} 1. Is there a way to combine the -a and --apple statements into one?

Yes, that's what zparseopts -M is for.  With -M, "-apple=a" means to
store anything you find for "--apple" in the location for "-a" instead.

 zparseopts -M -D -E -A MyVariableNameHere -- a b -orange -grape -apple=a

} 2. Are a series of 'if' statements the best way to handle these sorts of
} options?

If you're using "-A MyVariableNameHere" then you should be able to do

    # Cycle through the keys of the associative array
    for myOption in "${(k@)MyVariableNameHere}"
    do
      case "$myOption" in
      ...
      esac
    done

} ps - if anyone knows of a good place for zparseopts examples, please let me
} know. Google was not very much help.

The majority of uses of zparseopts are to interpret the options of some
*other* command, do some manipuation on them, and then construct a call
to that other command.  I.e., for writing a wrapper function around some
other complicated command.  So you won't find very many good examples of
doing something with everything that zparseopts parsed.

The only comprehensive example in the zsh distribution is the "zargs"
function, but it uses "-a array" instead of "-A hash" so the handling
of the parsed options might be too confusing for an introduction.

I wish I had a better suggestion.


  parent reply	other threads:[~2015-01-23 17:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 15:39 TJ Luoma
2015-01-23 16:37 ` ZyX
2015-01-23 17:15 ` Bart Schaefer [this message]
2015-01-23 17:56   ` Ray Andrews

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=150123091511.ZM1667@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).