Skip to content

Commit 02bd7cd

Browse files
author
Gauvain Pocentek
committed
rework the cmd line options
1 parent a9b5bf4 commit 02bd7cd

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

gitlab

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,22 @@ def actionHelpList(cls):
7777
return (l)
7878

7979
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]")
8181
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.")
8685
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.")
8988
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:")
9196

9297
classes = []
9398
for name, o in getmembers(gitlab):
@@ -112,7 +117,12 @@ verbose = False
112117

113118
args = []
114119
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+
116126
if arg.startswith('--'):
117127
arg = arg[2:]
118128

@@ -123,14 +133,33 @@ for arg in sys.argv[1:]:
123133
verbose = True
124134
continue
125135

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+
127147
k = k.strip().replace('-', '_')
128-
v = v.strip()
129148

130149
if k == 'gitlab':
131150
gitlab_id = v
132151
else:
133152
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)
134163
else:
135164
args.append(arg)
136165

@@ -155,7 +184,7 @@ try:
155184
what = args.pop(0)
156185
action = args.pop(0)
157186
except:
158-
die("Missing arguments")
187+
die("Missing arguments. Use `gitlab -h` for help.")
159188

160189
if action not in ['get', 'list', 'update', 'create', 'delete', 'help']:
161190
die("Unknown action: %s. Use \"gitlab %s help\" to get details." % (action, what))

0 commit comments

Comments
 (0)