Skip to content

Commit 28b7ec2

Browse files
committed
Updated documentation
1 parent b61728e commit 28b7ec2

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
also be colored.
77
* `help_error` - the error that prints when no help information can be found
88
* `default_error` - the error that prints when a non-existent command is run
9+
* The `with_argparser` decorators now add a Statement object to the `argparse.Namespace` object they pass
10+
to the `do_*` functions. It is stored in an attribute called `__statement__`. This can be useful if a command
11+
function needs to know the command line for things like logging.
912
* Potentially breaking changes
1013
* The following commands now write to stderr instead of stdout when printing an error. This will make catching
1114
errors easier in pyscript.

cmd2/cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser, preserve
199199
:param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
200200
:return: function that gets passed argparse-parsed args in a Namespace and a list of unknown argument strings
201201
A member called __statement__ is added to the Namespace to provide command functions access to the
202-
Statement object. This can be useful when knowledge of the command line is needed.
202+
Statement object. This can be useful if the command function needs to know the command line.
203203
204204
"""
205205
import functools
@@ -249,7 +249,7 @@ def with_argparser(argparser: argparse.ArgumentParser,
249249
:param preserve_quotes: if True, then arguments passed to argparse maintain their quotes
250250
:return: function that gets passed the argparse-parsed args in a Namespace
251251
A member called __statement__ is added to the Namespace to provide command functions access to the
252-
Statement object. This can be useful when knowledge of the command line is needed.
252+
Statement object. This can be useful if the command function needs to know the command line.
253253
"""
254254
import functools
255255

cmd2/parsing.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,10 @@ def tokenize(self, line: str, expand: bool = True) -> List[str]:
348348
Lex a string into a list of tokens. Shortcuts and aliases are expanded and comments are removed
349349
350350
:param line: the command line being lexed
351-
:param expand: if True, then aliases and shortcuts will be expanded
352-
set this to False if the first token does not need to be expanded
353-
because the command name is already known (Defaults to True)
351+
:param expand: If True, then aliases and shortcuts will be expanded.
352+
Set this to False if no expansion should occur because the command name is already known.
353+
Otherwise the command could be expanded if it matched an alias name. This is for cases where
354+
a do_* function was called manually (e.g do_help('alias').
354355
:return: A list of tokens
355356
:raises ValueError if there are unclosed quotation marks.
356357
"""
@@ -377,9 +378,10 @@ def parse(self, line: str, expand: bool = True) -> Statement:
377378
redirection directives.
378379
379380
:param line: the command line being parsed
380-
:param expand: if True, then aliases and shortcuts will be expanded
381-
set this to False if the first token does not need to be expanded
382-
because the command name is already known (Defaults to True)
381+
:param expand: If True, then aliases and shortcuts will be expanded.
382+
Set this to False if no expansion should occur because the command name is already known.
383+
Otherwise the command could be expanded if it matched an alias name. This is for cases where
384+
a do_* function was called manually (e.g do_help('alias').
383385
:return: A parsed Statement
384386
:raises ValueError if there are unclosed quotation marks
385387
"""

0 commit comments

Comments
 (0)