@@ -20,7 +20,6 @@ import os
2020import sys
2121
2222from ConfigParser import ConfigParser
23- from optparse import OptionParser
2423
2524from inspect import getmro
2625
@@ -30,19 +29,28 @@ def die(msg):
3029 sys .stderr .write (msg + "\n " )
3130 sys .exit (1 )
3231
33- # cmd line options
34- parser = OptionParser ()
35- parser .add_option ("-g" , "--gitlab" , dest = "gitlab_id" ,
36- help = "select the gitlab connection from the configuration file" ,
37- metavar = "GITLAB" )
38- (options , args ) = parser .parse_args ()
32+ gitlab_id = None
33+
34+ args = []
35+ d = {}
36+ for arg in sys .argv [1 :]:
37+ if arg .startswith ('--' ):
38+ k , v = arg .split ('=' , 2 )
39+ k = k [2 :].strip ()
40+ v = v .strip ()
41+
42+ if k == 'gitlab' :
43+ gitlab_id = v
44+ else :
45+ d [k ] = v
46+ else :
47+ args .append (arg )
3948
4049# read the config
4150config = ConfigParser ()
4251config .read (['/etc/python-gitlab.cfg' ,
4352 os .path .expanduser ('~/.python-gitlab.cfg' )])
4453
45- gitlab_id = options .gitlab_id
4654if gitlab_id is None :
4755 try :
4856 gitlab_id = config .get ('global' , 'default' )
@@ -79,16 +87,6 @@ if gitlab.GitlabObject not in getmro(cls):
7987 die ("Unknown object: %s" % what )
8088
8189if action == "create" :
82- d = {}
83- try :
84- for arg in args :
85- k , v = arg .split ("=" , 2 )
86- k = k .strip ()
87- v = v .strip ()
88- d [k ] = v
89- except :
90- die ("Impossible to parse data: %s" % arg )
91-
9290 try :
9391 o = cls (gl , d )
9492 o .save ()
@@ -98,16 +96,6 @@ if action == "create":
9896 sys .exit (0 )
9997
10098elif action == "list" :
101- d = {}
102- try :
103- for arg in args :
104- k , v = arg .split ("=" , 2 )
105- k = k .strip ()
106- v = v .strip ()
107- d [k ] = v
108- except :
109- die ("Impossible to parse data: %s" % arg )
110-
11199 try :
112100 l = cls .list (gl , ** d )
113101 except Exception as e :
@@ -121,19 +109,9 @@ elif action == "list":
121109
122110elif action == "get" :
123111 try :
124- id = args .pop (0 )
112+ id = d .pop ('id' )
125113 except :
126- die ("First arg must be the object id" )
127-
128- d = {}
129- try :
130- for arg in args :
131- k , v = arg .split ("=" , 2 )
132- k = k .strip ()
133- v = v .strip ()
134- d [k ] = v
135- except :
136- die ("Impossible to parse data: %s" % arg )
114+ die ("Missing --id argument" )
137115
138116 try :
139117 o = cls (gl , id , ** d )
@@ -146,19 +124,9 @@ elif action == "get":
146124
147125elif action == "delete" :
148126 try :
149- id = args .pop (0 )
127+ id = d .pop ('id' )
150128 except :
151- die ("First arg must be the object id" )
152-
153- d = {}
154- try :
155- for arg in args :
156- k , v = arg .split ("=" , 2 )
157- k = k .strip ()
158- v = v .strip ()
159- d [k ] = v
160- except :
161- die ("Impossible to parse data: %s" % arg )
129+ die ("Missing --id argument" )
162130
163131 try :
164132 o = cls (gl , id , ** d )
@@ -174,19 +142,9 @@ elif action == "delete":
174142
175143elif action == "update" :
176144 try :
177- id = args .pop (0 )
178- except :
179- die ("First arg must be the object id" )
180-
181- d = {}
182- try :
183- for arg in args :
184- k , v = arg .split ("=" , 2 )
185- k = k .strip ()
186- v = v .strip ()
187- d [k ] = v
145+ id = d .pop ('id' )
188146 except :
189- die ("Impossible to parse data: %s" % arg )
147+ die ("Missing --id argument" )
190148
191149 try :
192150 o = cls (gl , id , ** d )
0 commit comments