diff options
| author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-02-27 09:53:11 -0500 |
|---|---|---|
| committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-02-27 09:53:11 -0500 |
| commit | 5c23a4b66dff02e62f57e416319fc221ebeac291 (patch) | |
| tree | 835f6e936fa35da2f85ddbc2cd500bfd2fefa38e | |
| parent | b9a98aa3412b4c0882b2e3bb89c8a10463e93c97 (diff) | |
| parent | 0ee3d6bf3cd20877870d9542d858f8abb1e7f4f1 (diff) | |
| download | cmd2-git-5c23a4b66dff02e62f57e416319fc221ebeac291.tar.gz | |
Merge branch 'master' into unused_and_edit_fixes
| -rwxr-xr-x | cmd2.py | 12 | ||||
| -rw-r--r-- | docs/transcript.rst | 6 | ||||
| -rw-r--r-- | docs/unfreefeatures.rst | 5 | ||||
| -rw-r--r-- | tests/test_parsing.py | 24 |
4 files changed, 33 insertions, 14 deletions
@@ -30,6 +30,7 @@ import cmd import codecs import collections import datetime +import functools import glob import io import optparse @@ -271,6 +272,7 @@ def with_argument_list(func): method. Default passes a string of whatever the user typed. With this decorator, the decorated method will receive a list of arguments parsed from user input using shlex.split().""" + @functools.wraps(func) def cmd_wrapper(self, cmdline): lexed_arglist = parse_quoted_string(cmdline) func(self, lexed_arglist) @@ -288,6 +290,7 @@ def with_argparser_and_unknown_args(argparser, subcommand_names=None): :return: function that gets passed parsed args and a list of unknown args """ def arg_decorator(func): + @functools.wraps(func) def cmd_wrapper(instance, cmdline): lexed_arglist = parse_quoted_string(cmdline) args, unknown = argparser.parse_known_args(lexed_arglist) @@ -324,6 +327,7 @@ def with_argparser(argparser, subcommand_names=None): :return: function that gets passed parsed args """ def arg_decorator(func): + @functools.wraps(func) def cmd_wrapper(instance, cmdline): lexed_arglist = parse_quoted_string(cmdline) args = argparser.parse_args(lexed_arglist) @@ -387,6 +391,7 @@ def options(option_list, arg_desc="arg"): option_parser.set_usage("%s %s" % (func.__name__[3:], arg_desc)) option_parser._func = func + @functools.wraps(func) def new_func(instance, arg): """For @options commands this replaces the actual do_* methods in the instance __dict__. @@ -798,8 +803,6 @@ class Cmd(cmd.Cmd): allow_cli_args = True # Should arguments passed on the command-line be processed as commands? allow_redirection = True # Should output redirection and pipes be allowed default_to_shell = False # Attempt to run unrecognized commands as shell commands - excludeFromHistory = '''run ru r history histor histo hist his hi h edit edi ed e eof eo eos'''.split() - exclude_from_help = ['do_eof', 'do_eos', 'do__relative_load'] # Commands to exclude from the help menu reserved_words = [] # Attributes which ARE dynamically settable at runtime @@ -869,7 +872,12 @@ class Cmd(cmd.Cmd): # Call super class constructor. Need to do it in this way for Python 2 and 3 compatibility cmd.Cmd.__init__(self, completekey=completekey, stdin=stdin, stdout=stdout) + # Commands to exclude from the help menu or history command + self.exclude_from_help = ['do_eof', 'do_eos', 'do__relative_load'] + self.excludeFromHistory = '''history histor histo hist his hi h edit edi ed e eof eo eos'''.split() + self._finalize_app_parameters() + self.initial_stdout = sys.stdout self.history = History() self.pystate = {} diff --git a/docs/transcript.rst b/docs/transcript.rst index a2db3efd..36b35fcf 100644 --- a/docs/transcript.rst +++ b/docs/transcript.rst @@ -26,6 +26,12 @@ A transcript can automatically generated based upon commands previously executed This is by far the easiest way to generate a transcript. +.. warning:: + + Make sure you use the **poutput()** method in your ``cmd2`` application for generating command output. This method + of the ``cmd2.Cmd`` class ensure that output is properly redirected when redirecting to a file, piping to a shell + command, and when generating a transcript. + Manually -------- Here's a transcript created from ``python examples/example.py``:: diff --git a/docs/unfreefeatures.rst b/docs/unfreefeatures.rst index 2d497101..e92bf2d6 100644 --- a/docs/unfreefeatures.rst +++ b/docs/unfreefeatures.rst @@ -155,9 +155,14 @@ but ``print`` decreases output flexibility). ``cmd2`` applications can use ``self.poutput('output')``, ``self.pfeedback('message')``, and ``self.perror('errmsg')`` instead. These methods have these advantages: +- Handle output redirection to file and/or pipe appropriately - More concise - ``.pfeedback()`` destination is controlled by :ref:`quiet` parameter. +.. automethod:: cmd2.Cmd.poutput +.. automethod:: cmd2.Cmd.perror +.. automethod:: cmd2.Cmd.pfeedback + color ===== diff --git a/tests/test_parsing.py b/tests/test_parsing.py index da8f6692..5a741b57 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -27,10 +27,10 @@ def parser(): c.multilineCommands = ['multiline'] c.case_insensitive = True c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands, - legalChars=c.legalChars, commentGrammars=c.commentGrammars, - commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive, - blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser, - preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts) + legalChars=c.legalChars, commentGrammars=c.commentGrammars, + commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive, + blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser, + preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts) return c.parser_manager.main_parser # Case-insensitive ParserManager @@ -40,10 +40,10 @@ def ci_pm(): c.multilineCommands = ['multiline'] c.case_insensitive = True c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands, - legalChars=c.legalChars, commentGrammars=c.commentGrammars, - commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive, - blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser, - preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts) + legalChars=c.legalChars, commentGrammars=c.commentGrammars, + commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive, + blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser, + preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts) return c.parser_manager # Case-sensitive ParserManager @@ -53,10 +53,10 @@ def cs_pm(): c.multilineCommands = ['multiline'] c.case_insensitive = False c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands, - legalChars=c.legalChars, commentGrammars=c.commentGrammars, - commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive, - blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser, - preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts) + legalChars=c.legalChars, commentGrammars=c.commentGrammars, + commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive, + blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser, + preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts) return c.parser_manager |
