Skip to content

Commit 97396ff

Browse files
authored
Merge branch 'master' into docstr_fmt
2 parents a9ea11f + d3a9a6d commit 97396ff

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ Instructions for implementing each feature follow.
123123
example in conjunction with the [conditional.py](https://github.com/python-cmd2/cmd2/blob/master/examples/scripts/conditional.py) script
124124

125125
- Parsing commands with `argparse`
126-
- Two decorators provide built-in capability for using `argparse.ArgumentParser` to parse command arguments
127-
- `cmd2.with_argparser` - all arguments are parsed by the `ArgumentParser`
128-
- `cmd2.with_argparser_and_unknown_args` - any arguments not parsed by the `ArgumentParser` get passed as a list
126+
- The built-in `cmd2.with_argparser` decorator will parse arguments using `argparse.ArgumentParser`
127+
- Optionally, `cmd2.with_argparser(.., with_unknown_args=True)` can be used to pass all unknown arguments as a list
129128

130129
```Python
131130
import argparse

cmd2/parsing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ class Statement(str):
9191
Tips:
9292
9393
1. `argparse <https://docs.python.org/3/library/argparse.html>`_ is your
94-
friend for anything complex. ``cmd2`` has two decorators
95-
(:func:`~cmd2.decorators.with_argparser`, and
96-
:func:`~cmd2.decorators.with_argparser_and_unknown_args`) which you can
94+
friend for anything complex. ``cmd2`` has the decorator
95+
(:func:`~cmd2.decorators.with_argparser`) which you can
9796
use to make your command method receive a namespace of parsed arguments,
9897
whether positional or denoted with switches.
9998

docs/features/argument_processing.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ applications.
3535
passed to commands:
3636

3737
* :func:`cmd2.decorators.with_argparser`
38-
* :func:`cmd2.decorators.with_argparser_and_unknown_args`
3938
* :func:`cmd2.decorators.with_argument_list`
4039

4140
All of these decorators accept an optional **preserve_quotes** argument which
@@ -262,12 +261,12 @@ Unknown Positional Arguments
262261

263262
If you want all unknown arguments to be passed to your command as a list of
264263
strings, then decorate the command method with the
265-
``@with_argparser_and_unknown_args`` decorator.
264+
``@with_argparser(..., with_unknown_args=True)`` decorator.
266265

267266
Here's what it looks like::
268267

269268
import argparse
270-
from cmd2 import with_argparser_and_unknown_args
269+
from cmd2 import with_argparser
271270

272271
dir_parser = argparse.ArgumentParser()
273272
dir_parser.add_argument('-l', '--long', action='store_true', help="display in long format with one item per line")
@@ -292,9 +291,8 @@ Using A Custom Namespace
292291

293292
In some cases, it may be necessary to write custom ``argparse`` code that is
294293
dependent on state data of your application. To support this ability while
295-
still allowing use of the decorators, both ``@with_argparser`` and
296-
``@with_argparser_and_unknown_args`` have an optional argument called
297-
``ns_provider``.
294+
still allowing use of the decorators, ``@with_argparser`` has an optional
295+
argument called ``ns_provider``.
298296

299297
``ns_provider`` is a Callable that accepts a ``cmd2.Cmd`` object as an argument
300298
and returns an ``argparse.Namespace``::
@@ -320,9 +318,8 @@ logic.
320318
Subcommands
321319
------------
322320

323-
Subcommands are supported for commands using either the ``@with_argparser`` or
324-
``@with_argparser_and_unknown_args`` decorator. The syntax for supporting them
325-
is based on argparse sub-parsers.
321+
Subcommands are supported for commands using the ``@with_argparser`` decorator.
322+
The syntax is based on argparse sub-parsers.
326323

327324
You may add multiple layers of subcommands for your command. ``cmd2`` will
328325
automatically traverse and tab complete subcommands for all commands using
@@ -350,8 +347,8 @@ help output.
350347
Decorator Order
351348
---------------
352349

353-
If you are using custom decorators in combination with either
354-
``@cmd2.with_argparser`` or ``@cmd2.with_argparser_and_unknown_args``, then the
350+
If you are using custom decorators in combination with
351+
``@cmd2.with_argparser``, then the
355352
order of your custom decorator(s) relative to the ``cmd2`` decorator matters
356353
when it comes to runtime behavior and ``argparse`` errors. There is nothing
357354
``cmd2``-specific here, this is just a side-effect of how decorators work in

0 commit comments

Comments
 (0)