curses = None
-def define(name, default=None, type=str, help=None, metavar=None,
+def define(name, default=None, type=None, help=None, metavar=None,
multiple=False):
"""Defines a new command line option.
- If type is given (one of str, float, int, datetime, or timedelta),
- we parse the command line arguments based on the given type. If
- multiple is True, we accept comma-separated values, and the option
- value is always a list.
+ If type is given (one of str, float, int, datetime, or timedelta)
+ or can be inferred from the default, we parse the command line
+ arguments based on the given type. If multiple is True, we accept
+ comma-separated values, and the option value is always a list.
For multi-value integers, we also accept the syntax x:y, which
turns into range(x, y) - very useful for long integer ranges.
options_file = frame.f_code.co_filename
file_name = frame.f_back.f_code.co_filename
if file_name == options_file: file_name = ""
+ if type is None:
+ if not multiple and default is not None:
+ type = default.__class__
+ else:
+ type = str
options[name] = _Option(name, file_name=file_name, default=default,
type=type, help=help, metavar=metavar,
multiple=multiple)