# HG changeset patch # User catherine.devlin@gmail.com # Date 1314300296 14400 # Node ID bfbe4241bd6bd3b849e6da60c47b6e8acc5dbcb6 # Parent 742fd308f0c976c402903886716fe1e7832df040 custom double-redirector fixed diff -r 742fd308f0c9 -r bfbe4241bd6b cmd2.py --- a/cmd2.py Sun Aug 21 02:39:43 2011 -0400 +++ b/cmd2.py Thu Aug 25 15:24:56 2011 -0400 @@ -379,6 +379,7 @@ debug = False locals_in_py = True kept_state = None + redirector = '>' # for sending output to file settable = stubbornDict(''' prompt colors Colorized output (*nix only) @@ -665,7 +666,10 @@ - args: if "quoted strings /* seem to " start comments? - command: what ''' - outputParser = (pyparsing.Literal('>>') | (pyparsing.WordStart() + '>') | pyparsing.Regex('[^=]>'))('output') + #outputParser = (pyparsing.Literal('>>') | (pyparsing.WordStart() + '>') | pyparsing.Regex('[^=]>'))('output') + outputParser = (pyparsing.Literal(self.redirector *2) | \ + (pyparsing.WordStart() + self.redirector) | \ + pyparsing.Regex('[^=]' + self.redirector))('output') terminatorParser = pyparsing.Or([(hasattr(t, 'parseString') and t) or pyparsing.Literal(t) for t in self.terminators])('terminator') stringEnd = pyparsing.stringEnd ^ '\nEOF' @@ -815,7 +819,7 @@ self.kept_sys = Statekeeper(sys, ('stdout',)) if statement.parsed.outputTo: mode = 'w' - if statement.parsed.output == '>>': + if statement.parsed.output == 2 * self.redirector: mode = 'a' sys.stdout = self.stdout = open(os.path.expanduser(statement.parsed.outputTo), mode) else: diff -r 742fd308f0c9 -r bfbe4241bd6b docs/freefeatures.rst --- a/docs/freefeatures.rst Sun Aug 21 02:39:43 2011 -0400 +++ b/docs/freefeatures.rst Thu Aug 25 15:24:56 2011 -0400 @@ -76,6 +76,22 @@ to paste buffer requires software to be installed on the operating system, pywin32_ on Windows or xclip_ on \*nix. +If your application depends on mathematical syntax, ``>`` may be a bad +choice for redirecting output - it will prevent you from using the +greater-than sign in your actual user commands. You can override your +app's value of ``self.redirector`` to use a different string for output redirection:: + + class MyApp(cmd2.Cmd): + redirector = '->' + +:: + + (Cmd) say line1 -> out.txt + (Cmd) say line2 ->-> out.txt + (Cmd) !cat out.txt + line1 + line2 + .. _pywin32: http://sourceforge.net/projects/pywin32/ .. _xclip: http://www.cyberciti.biz/faq/xclip-linux-insert-files-command-output-intoclipboard/ diff -r 742fd308f0c9 -r bfbe4241bd6b example/example.py --- a/example/example.py Sun Aug 21 02:39:43 2011 -0400 +++ b/example/example.py Thu Aug 25 15:24:56 2011 -0400 @@ -7,6 +7,7 @@ multilineCommands = ['orate'] Cmd.shortcuts.update({'&': 'speak'}) maxrepeats = 3 + redirector = '->' Cmd.settable.append('maxrepeats Max number of `--repeat`s allowed') @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"),