##// END OF EJS Templates
Use an unique object instead of specified flag
Takafumi Arakaki -
Show More
@@ -21,7 +21,7 b' from IPython.external.argparse import Action'
21 # Our own packages
21 # Our own packages
22 from IPython.core.error import StdinNotImplementedError
22 from IPython.core.error import StdinNotImplementedError
23 from IPython.core.magic import Magics, magics_class, line_magic
23 from IPython.core.magic import Magics, magics_class, line_magic
24 from IPython.core.magic_arguments import (argument, defaults, magic_arguments,
24 from IPython.core.magic_arguments import (argument, magic_arguments,
25 parse_argstring)
25 parse_argstring)
26 from IPython.testing.skipdoctest import skip_doctest
26 from IPython.testing.skipdoctest import skip_doctest
27 from IPython.utils import io
27 from IPython.utils import io
@@ -31,10 +31,7 b' from IPython.utils import io'
31 #-----------------------------------------------------------------------------
31 #-----------------------------------------------------------------------------
32
32
33
33
34 class HistoryArgLimitAction(Action):
34 _unspecified = object()
35 def __call__(self, parser, namespace, values, option_string=None):
36 namespace.limit_specified = True
37 namespace.limit = values
38
35
39
36
40 @magics_class
37 @magics_class
@@ -87,13 +84,12 b' class HistoryMagics(Magics):'
87 full saved history (may be very long).
84 full saved history (may be very long).
88 """)
85 """)
89 @argument(
86 @argument(
90 '-l', dest='limit', type=int, nargs='?', action=HistoryArgLimitAction,
87 '-l', dest='limit', type=int, nargs='?', default=_unspecified,
91 help="""
88 help="""
92 get the last n lines from all sessions. Specify n as a single
89 get the last n lines from all sessions. Specify n as a single
93 arg, or the default is the last 10 lines.
90 arg, or the default is the last 10 lines.
94 """)
91 """)
95 @argument('range', nargs='*')
92 @argument('range', nargs='*')
96 @defaults(limit_specified=False)
97 @skip_doctest
93 @skip_doctest
98 @line_magic
94 @line_magic
99 def history(self, parameter_s = ''):
95 def history(self, parameter_s = ''):
@@ -165,6 +161,7 b' class HistoryMagics(Magics):'
165 raw = args.raw
161 raw = args.raw
166
162
167 pattern = None
163 pattern = None
164 limit = None if args.limit is _unspecified else args.limit
168
165
169 if args.pattern is not None:
166 if args.pattern is not None:
170 if args.pattern:
167 if args.pattern:
@@ -172,10 +169,10 b' class HistoryMagics(Magics):'
172 else:
169 else:
173 pattern = "*"
170 pattern = "*"
174 hist = history_manager.search(pattern, raw=raw, output=get_output,
171 hist = history_manager.search(pattern, raw=raw, output=get_output,
175 n=args.limit)
172 n=limit)
176 print_nums = True
173 print_nums = True
177 elif args.limit_specified:
174 elif args.limit is not _unspecified:
178 n = 10 if args.limit is None else args.limit
175 n = 10 if limit is None else limit
179 hist = history_manager.get_tail(n, raw=raw, output=get_output)
176 hist = history_manager.get_tail(n, raw=raw, output=get_output)
180 else:
177 else:
181 if args.range: # Get history by ranges
178 if args.range: # Get history by ranges
General Comments 0
You need to be logged in to leave comments. Login now