globaloptions were simply dropped after parsing, fold them in regular options
authorAlexander Solovyov <piranha@piranha.org.ua>
Thu, 03 Sep 2009 22:06:14 +0300
changeset 81 c93635699e2a
parent 80 eacc0c57f0e6
child 82 074c1768759a
globaloptions were simply dropped after parsing, fold them in regular options
opster.py
test.py
--- a/opster.py	Wed Sep 02 12:50:52 2009 +0300
+++ b/opster.py	Thu Sep 03 22:06:14 2009 +0300
@@ -316,10 +316,9 @@
 # --------
 
 def _dispatch(args, cmdtable, globalopts):
-    cmd, func, args, options, globaloptions = cmdparse(args, cmdtable,
-                                                       globalopts)
+    cmd, func, args, options = cmdparse(args, cmdtable, globalopts)
 
-    if globaloptions['help']:
+    if options.pop('help', False):
         return 'help', cmdtable['help'][0], [cmd], {}
     elif not cmd:
         return 'help', cmdtable['help'][0], ['shortlist'], {}
@@ -350,12 +349,7 @@
     except getopt.GetoptError, e:
         raise ParseError(cmd, e)
 
-    globaloptions = {}
-    for o in globalopts:
-        name = o[1]
-        globaloptions[name] = options.pop(name)
-
-    return (cmd, cmd and info[0] or None, args, options, globaloptions)
+    return (cmd, cmd and info[0] or None, args, options)
 
 def findpossible(cmd, table):
     """
--- a/test.py	Wed Sep 02 12:50:52 2009 +0300
+++ b/test.py	Thu Sep 03 22:06:14 2009 +0300
@@ -28,7 +28,10 @@
     if opts.get('pass'):
         return
     # test ui
-    ui.write('preved\n')
+    ui.write('write\n')
+    ui.note('note\n')
+    ui.info('info\n')
+    ui.warn('warn\n')
     if opts.get('exit'):
         sys.exit(opts['exit'])
 
@@ -82,5 +85,3 @@
 
 if __name__ == '__main__':
     dispatch(globaloptions=UI.options, middleware=ui_middleware)
-
-