--- a/fancycmd.py Sat Jun 27 22:17:18 2009 +0300
+++ b/fancycmd.py Sun Jun 28 10:19:15 2009 +0300
@@ -11,12 +11,14 @@
# Public interface
# --------
-def fancyopts(cmd, usage, options, args):
- if not args:
- cmd_help(cmd, usage, options)
- else:
- opts, args = parse(args, options)
- cmd(*args, **opts)
+def fancyopts(cmd, options, usage):
+ def inner(args):
+ if not args:
+ cmd_help(cmd, usage, options)
+ else:
+ opts, args = parse(args, options)
+ cmd(*args, **opts)
+ return inner
def dispatch(args, cmdtable, globalopts=None):
'''Dispatch command arguments based on subcommands.
--- a/test_opts.py Sat Jun 27 22:17:18 2009 +0300
+++ b/test_opts.py Sun Jun 28 10:19:15 2009 +0300
@@ -17,4 +17,4 @@
print opts.get('pid_file')
if __name__ == '__main__':
- fancyopts(main, '%s [-l HOST] DIR' % sys.argv[0], opts, sys.argv[1:])
+ fancyopts(main, opts, usage='%s [-l HOST] DIR' % sys.argv[0])(sys.argv[1:])