Skip to content

Commit d0654e1

Browse files
committed
Added warning to documentation about how help_foo won't be called for command foo if it uses an argparse decorator
Also: - Renamed argparse_example.py to decorator_example.py
1 parent e018924 commit d0654e1

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* Never - output methods strip all ANSI escape sequences
3535
* Added ``macro`` command to create macros, which are similar to aliases, but can take arguments when called
3636
* All cmd2 command functions have been converted to use argparse.
37+
* Renamed argparse_example.py to decorator_example.py to help clarify its intent
3738
* Deprecations
3839
* Deprecated the built-in ``cmd2`` support for colors including ``Cmd.colorize()`` and ``Cmd._colorcodes``
3940
* Deletions (potentially breaking changes)

docs/argument_processing.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Argument Processing
1515

1616
These features are all provided by the ``@with_argparser`` decorator which is importable from ``cmd2``.
1717

18-
See the either the argprint_ or argparse_ example to learn more about how to use the various ``cmd2`` argument
18+
See the either the argprint_ or decorator_ example to learn more about how to use the various ``cmd2`` argument
1919
processing decorators in your ``cmd2`` applications.
2020

2121
.. _argprint: https://github.com/python-cmd2/cmd2/blob/master/examples/arg_print.py
22-
.. _argparse: https://github.com/python-cmd2/cmd2/blob/master/examples/argparse_example.py
22+
.. _decorator: https://github.com/python-cmd2/cmd2/blob/master/examples/decorator_example.py
2323

2424
Using the argument parser decorator
2525
===================================
@@ -171,6 +171,14 @@ Which yields:
171171
172172
This command can not generate tags with no content, like <br/>
173173
174+
.. warning::
175+
176+
If a command **foo** is decorated with one of cmd2's argparse decorators, then **help_foo** will not
177+
be invoked when ``help foo`` is called. The argparse_ module provides a rich API which can be used to
178+
tweak every aspect of the displayed help and we encourage ``cmd2`` developers to utilize that.
179+
180+
.. _argparse: https://docs.python.org/3/library/argparse.html
181+
174182

175183
Grouping Commands
176184
=================
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/usr/bin/env python
22
# coding=utf-8
3-
"""A sample application for cmd2 showing how to use argparse to
3+
"""A sample application showing how to use cmd2's argparse decorators to
44
process command line arguments for your application.
55
66
Thanks to cmd2's built-in transcript testing capability, it also
7-
serves as a test suite for argparse_example.py when used with the
8-
exampleSession.txt transcript.
7+
serves as a test suite when used with the exampleSession.txt transcript.
98
10-
Running `python argparse_example.py -t exampleSession.txt` will run
11-
all the commands in the transcript against argparse_example.py,
9+
Running `python decorator_example.py -t exampleSession.txt` will run
10+
all the commands in the transcript against decorator_example.py,
1211
verifying that the output produced matches the transcript.
1312
"""
1413
import argparse

examples/transcripts/exampleSession.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Run this transcript with "python argparse_example.py -t exampleSession.txt"
1+
# Run this transcript with "python decorator_example.py -t exampleSession.txt"
22
# The regex for colors is because no color on Windows.
33
# The regex for editor will match whatever program you use.
44
# regexes on prompts just make the trailing space obvious

0 commit comments

Comments
 (0)