backward incompatible change: require argv=sys.argv[1:] for @wrapped command to parse command line
--- a/docs/changelog.rst Tue Sep 22 14:24:57 2009 +0300
+++ b/docs/changelog.rst Sun Sep 27 23:24:44 2009 +0300
@@ -1,6 +1,16 @@
Changelog
---------
+0.9.10
+~~~~~~
+
+ - **backward incompatible change**: if you are calling function to parse
+ command line, earlier you could write ``main()`` to accomplish that
+ task. This syntax is unavailable now (this will try to actually call a
+ function), and you should use ``main(argv=sys.argv[1:])``.
+ - if default value of an option is a fuction, always call it (None is passed in
+ case when option is not supplied)
+
0.9.9
~~~~~
- Now it's possible to call commands as regular function, where every
--- a/docs/overview.rst Tue Sep 22 14:24:57 2009 +0300
+++ b/docs/overview.rst Sun Sep 27 23:24:44 2009 +0300
@@ -58,17 +58,18 @@
After that you can simply call this function as an entry point to your program::
if __name__ == '__main__':
- main()
+ main(argv=sys.argv[1:])
This will run command line parsing facility, using arguments from
-``sys.argv``. ``%name`` will be replaced with ``sys.argv[0]`` (or prepended to
-usage string if there is no ``%name``), and rest of arguments will be passed to
-command line parser. In case if rest is empty, help will be displayed.
+``sys.argv``. ``%name`` in usage string will be replaced with ``sys.argv[0]``
+(or prepended to usage string if there is no ``%name``), and rest of arguments
+will be passed to command line parser. In case if rest is empty, help will be
+displayed.
Of course, you can use your function programmatically, supplying list of
arguments to function::
- main('-l 0.0.0.0 /my/dir'.split())
+ main(argv='-l 0.0.0.0 /my/dir'.split())
Or, if you need this, you can call this function as usual::
--- a/opster.py Tue Sep 22 14:24:57 2009 +0300
+++ b/opster.py Sun Sep 27 23:24:44 2009 +0300
@@ -74,9 +74,6 @@
# no catcher here because this is call from Python
return call_cmd_regular(func, options_)(*args, **opts)
- if argv is None:
- argv = sys.argv[1:]
-
try:
opts, args = catcher(lambda: parse(argv, options_), help_func)
except Abort:
--- a/test_opts.py Tue Sep 22 14:24:57 2009 +0300
+++ b/test_opts.py Sun Sep 27 23:24:44 2009 +0300
@@ -30,5 +30,5 @@
print locals()
if __name__ == '__main__':
- #main()
- another()
+ #main(argv=sys.argv[1:])
+ another(argv=sys.argv[1:])