Mercurial > python-cmd2
comparison cmd2.py @ 432:e4d6edca469b
get history in script form
author | catherine.devlin@gmail.com |
---|---|
date | Sun, 31 Jul 2011 16:57:15 -0400 |
parents | 73e741441ac0 |
children | 5a814cb007ae |
comparison
equal
deleted
inserted
replaced
431:f1ed2907ccab | 432:e4d6edca469b |
---|---|
1055 (sys.version, sys.platform, cprt, self.__class__.__name__, self.do_py.__doc__)) | 1055 (sys.version, sys.platform, cprt, self.__class__.__name__, self.do_py.__doc__)) |
1056 except EmbeddedConsoleExit: | 1056 except EmbeddedConsoleExit: |
1057 pass | 1057 pass |
1058 keepstate.restore() | 1058 keepstate.restore() |
1059 | 1059 |
1060 def do_history(self, arg): | 1060 @options([make_option('-s', '--script', action="store_true", help="Script format; no separation lines"), |
1061 ], arg_desc = '(limit on which commands to include)') | |
1062 def do_history(self, arg, opts): | |
1061 """history [arg]: lists past commands issued | 1063 """history [arg]: lists past commands issued |
1062 | 1064 |
1063 | no arg: list all | 1065 | no arg: list all |
1064 | arg is integer: list one history item, by index | 1066 | arg is integer: list one history item, by index |
1065 | arg is string: string search | 1067 | arg is string: string search |
1068 if arg: | 1070 if arg: |
1069 history = self.history.get(arg) | 1071 history = self.history.get(arg) |
1070 else: | 1072 else: |
1071 history = self.history | 1073 history = self.history |
1072 for hi in history: | 1074 for hi in history: |
1073 self.stdout.write(hi.pr()) | 1075 if opts.script: |
1076 self.poutput(hi) | |
1077 else: | |
1078 self.stdout.write(hi.pr()) | |
1074 def last_matching(self, arg): | 1079 def last_matching(self, arg): |
1075 try: | 1080 try: |
1076 if arg: | 1081 if arg: |
1077 return self.history.get(arg)[-1] | 1082 return self.history.get(arg)[-1] |
1078 else: | 1083 else: |