@@ -77,17 +77,22 @@ def actionHelpList(cls):
77
77
return (l )
78
78
79
79
def usage ():
80
- print ("usage: gitlab [--help] [--gitlab=GITLAB ] [--fancy] what action [options]" )
80
+ print ("usage: gitlab [--help|-h ] [--fancy|--verbose|-v ] [--gitlab=GITLAB] WHAT ACTION [options]" )
81
81
print ("" )
82
- print ("--gitlab=GITLAB: Specifies which python-gitlab.cfg configuration section should be used." )
83
- print (" If not defined, the default selection will be used." )
84
- print ("--fancy : More verbose output." )
85
- print ("--help : Displays this message." )
82
+ print ("--gitlab=GITLAB" )
83
+ print (" Specifies which python-gitlab.cfg configuration section should be used." )
84
+ print (" If not defined, the default selection will be used." )
86
85
print ("" )
87
- print ("Available `options` depend on which what/action couple is used. " )
88
- print ("If `action` is \" help \" , available actions and options will be listed for `what` ." )
86
+ print ("--fancy, --verbose, -v " )
87
+ print (" More verbose output ." )
89
88
print ("" )
90
- print ("Available `what` values are:" )
89
+ print ("--help, -h" )
90
+ print (" Displays this message." )
91
+ print ("" )
92
+ print ("Available `options` depend on which WHAT/ACTION couple is used." )
93
+ print ("If `ACTION` is \" help\" , available actions and options will be listed for `ACTION`." )
94
+ print ("" )
95
+ print ("Available `WHAT` values are:" )
91
96
92
97
classes = []
93
98
for name , o in getmembers (gitlab ):
@@ -112,7 +117,12 @@ verbose = False
112
117
113
118
args = []
114
119
d = {}
115
- for arg in sys .argv [1 :]:
120
+ keep_looping = False
121
+ for idx , arg in enumerate (sys .argv [1 :], 1 ):
122
+ if keep_looping :
123
+ keep_looping = False
124
+ continue
125
+
116
126
if arg .startswith ('--' ):
117
127
arg = arg [2 :]
118
128
@@ -123,14 +133,33 @@ for arg in sys.argv[1:]:
123
133
verbose = True
124
134
continue
125
135
126
- k , v = arg .split ('=' , 1 )
136
+ try :
137
+ k , v = arg .split ('=' , 1 )
138
+ v .strip ()
139
+ except :
140
+ k = arg
141
+ try :
142
+ v = sys .argv [idx + 1 ]
143
+ except :
144
+ die ("--%s argument requires a value" % arg )
145
+ keep_looping = True
146
+
127
147
k = k .strip ().replace ('-' , '_' )
128
- v = v .strip ()
129
148
130
149
if k == 'gitlab' :
131
150
gitlab_id = v
132
151
else :
133
152
d [k ] = v
153
+ elif arg .startswith ('-' ):
154
+ arg = arg [1 :]
155
+
156
+ if arg == 'h' :
157
+ usage ()
158
+ sys .exit (0 )
159
+ elif arg == 'v' :
160
+ verbose = True
161
+ else :
162
+ die ("Unknown argument: -%s" % arg )
134
163
else :
135
164
args .append (arg )
136
165
155
184
what = args .pop (0 )
156
185
action = args .pop (0 )
157
186
except :
158
- die ("Missing arguments" )
187
+ die ("Missing arguments. Use `gitlab -h` for help. " )
159
188
160
189
if action not in ['get' , 'list' , 'update' , 'create' , 'delete' , 'help' ]:
161
190
die ("Unknown action: %s. Use \" gitlab %s help\" to get details." % (action , what ))
0 commit comments