The PEAK Developers' Center   Diff for "OptionsHowTo" UserPreferences
HelpContents Search Diffs Info Edit Subscribe XML Print View
Differences between version dated 2004-11-26 20:44:57 and 2004-11-28 14:34:06
Deletions are marked like this.
Additions are marked like this.

is encountered on a command line. You must specify ``repeatable=True`` if you
want to allow the option to appear more than once on the command line.
The ``zapify`` function above will be called on a ``Bar`` instance if it
The ``zapify`` function above will be called on a ``Foo`` instance if it
parses a ``-z`` option. `parser` is the ``optparse.OptionParser`` being used
to do the parsing, `optname` is the option name (e.g. ``-z``) that was
encountered, `optval` is either the option's argument or the `value`

    >>> foo.verbose
* Stop processing options after first argument::
    >>> foo = Foo(); options.parse(foo, ['xyz', '-v'])
    ['xyz', '-v']
    >>> foo.verbose
* Unless interspersed arguments are allowed (see `Parser Settings`_ below)::
    >>> foo = Foo()
    >>> options.parse(foo, ['xyz', '-v'], allow_interspersed_args=True)
    >>> foo.verbose
* Two options::
    >>> foo = Foo(); options.parse(foo, ['-v', '-q'])

blank lines in the real output. Doctest doesn't allow blank lines to appear
in sample output.)
Also, one keyword argument is allow that is not actually an ``OptionParser``
keyword argument: ``allow_interspersed_args``. If this keyword is not set
to a true value, option parsing stops at the first non-option argument
encountered. (This is the desired default behavior for PEAK commands, to
prevent them trying to parse subcommands' options.)
Option Groups

    This sets additional text, if any, that should appear after the group
    title, but before the options in that group are listed.
    title, but before the options in that group are listed. ``optparase``
    treats this as a single paragraph of text and may rewrap it, so don't
    bother with any fancy formatting.
    The sort key is a value used to arrange groups in a specified order.

As you can see, the ``bang`` attribute had its default value until we looked
at ``parsed_args``, at which point it was set according to the supplied
options. (Note: the ``"foo"`` in the ``argv`` parameter is the "program name";
that's why it doesn't appear in ``cmd.parsed_args``.)
options. (Note: the ``"foo"`` in the ``argv`` parameter is the "program name",
which is why it doesn't appear in ``cmd.parsed_args``.)
Finally, you should be aware that both the help generation and option parsing
are done via the ``option_parser`` attribute of the command, which is

* Help formatter column setting, style setting
* Allow use of interspersed args+options
* Allow multi-valued args (``nargs>1``)?

ShowText of this page
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck