Skip to content

Commit 5c23a4b

Browse files
committed
Merge branch 'master' into unused_and_edit_fixes
2 parents b9a98aa + 0ee3d6b commit 5c23a4b

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

cmd2.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import codecs
3131
import collections
3232
import datetime
33+
import functools
3334
import glob
3435
import io
3536
import optparse
@@ -271,6 +272,7 @@ def with_argument_list(func):
271272
method. Default passes a string of whatever the user typed.
272273
With this decorator, the decorated method will receive a list
273274
of arguments parsed from user input using shlex.split()."""
275+
@functools.wraps(func)
274276
def cmd_wrapper(self, cmdline):
275277
lexed_arglist = parse_quoted_string(cmdline)
276278
func(self, lexed_arglist)
@@ -288,6 +290,7 @@ def with_argparser_and_unknown_args(argparser, subcommand_names=None):
288290
:return: function that gets passed parsed args and a list of unknown args
289291
"""
290292
def arg_decorator(func):
293+
@functools.wraps(func)
291294
def cmd_wrapper(instance, cmdline):
292295
lexed_arglist = parse_quoted_string(cmdline)
293296
args, unknown = argparser.parse_known_args(lexed_arglist)
@@ -324,6 +327,7 @@ def with_argparser(argparser, subcommand_names=None):
324327
:return: function that gets passed parsed args
325328
"""
326329
def arg_decorator(func):
330+
@functools.wraps(func)
327331
def cmd_wrapper(instance, cmdline):
328332
lexed_arglist = parse_quoted_string(cmdline)
329333
args = argparser.parse_args(lexed_arglist)
@@ -387,6 +391,7 @@ def option_setup(func):
387391
option_parser.set_usage("%s %s" % (func.__name__[3:], arg_desc))
388392
option_parser._func = func
389393

394+
@functools.wraps(func)
390395
def new_func(instance, arg):
391396
"""For @options commands this replaces the actual do_* methods in the instance __dict__.
392397
@@ -798,8 +803,6 @@ class Cmd(cmd.Cmd):
798803
allow_cli_args = True # Should arguments passed on the command-line be processed as commands?
799804
allow_redirection = True # Should output redirection and pipes be allowed
800805
default_to_shell = False # Attempt to run unrecognized commands as shell commands
801-
excludeFromHistory = '''run ru r history histor histo hist his hi h edit edi ed e eof eo eos'''.split()
802-
exclude_from_help = ['do_eof', 'do_eos', 'do__relative_load'] # Commands to exclude from the help menu
803806
reserved_words = []
804807

805808
# Attributes which ARE dynamically settable at runtime
@@ -869,7 +872,12 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, persistent_histor
869872
# Call super class constructor. Need to do it in this way for Python 2 and 3 compatibility
870873
cmd.Cmd.__init__(self, completekey=completekey, stdin=stdin, stdout=stdout)
871874

875+
# Commands to exclude from the help menu or history command
876+
self.exclude_from_help = ['do_eof', 'do_eos', 'do__relative_load']
877+
self.excludeFromHistory = '''history histor histo hist his hi h edit edi ed e eof eo eos'''.split()
878+
872879
self._finalize_app_parameters()
880+
873881
self.initial_stdout = sys.stdout
874882
self.history = History()
875883
self.pystate = {}

docs/transcript.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ A transcript can automatically generated based upon commands previously executed
2626

2727
This is by far the easiest way to generate a transcript.
2828

29+
.. warning::
30+
31+
Make sure you use the **poutput()** method in your ``cmd2`` application for generating command output. This method
32+
of the ``cmd2.Cmd`` class ensure that output is properly redirected when redirecting to a file, piping to a shell
33+
command, and when generating a transcript.
34+
2935
Manually
3036
--------
3137
Here's a transcript created from ``python examples/example.py``::

docs/unfreefeatures.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,14 @@ but ``print`` decreases output flexibility). ``cmd2`` applications can use
155155
``self.poutput('output')``, ``self.pfeedback('message')``, and ``self.perror('errmsg')``
156156
instead. These methods have these advantages:
157157

158+
- Handle output redirection to file and/or pipe appropriately
158159
- More concise
159160
- ``.pfeedback()`` destination is controlled by :ref:`quiet` parameter.
160161

162+
.. automethod:: cmd2.Cmd.poutput
163+
.. automethod:: cmd2.Cmd.perror
164+
.. automethod:: cmd2.Cmd.pfeedback
165+
161166

162167
color
163168
=====

tests/test_parsing.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def parser():
2727
c.multilineCommands = ['multiline']
2828
c.case_insensitive = True
2929
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands,
30-
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
31-
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
32-
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
33-
preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts)
30+
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
31+
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
32+
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
33+
preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts)
3434
return c.parser_manager.main_parser
3535

3636
# Case-insensitive ParserManager
@@ -40,10 +40,10 @@ def ci_pm():
4040
c.multilineCommands = ['multiline']
4141
c.case_insensitive = True
4242
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands,
43-
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
44-
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
45-
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
46-
preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts)
43+
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
44+
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
45+
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
46+
preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts)
4747
return c.parser_manager
4848

4949
# Case-sensitive ParserManager
@@ -53,10 +53,10 @@ def cs_pm():
5353
c.multilineCommands = ['multiline']
5454
c.case_insensitive = False
5555
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands,
56-
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
57-
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
58-
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
59-
preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts)
56+
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
57+
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
58+
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
59+
preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts)
6060
return c.parser_manager
6161

6262

0 commit comments

Comments
 (0)