Pārlūkot izejas kodu

Add support for -h/--help options.

RHBZ#962168. In response to user request added support for invoking with the -h
or --help argument to print usage information. Previously usage was only
printed if the user provided less than two arguments AND did not provide any
invalid arguments, as they were unhandled the commonly used -h and --help
arguments counted as invalid.

https://bugzilla.redhat.com/show_bug.cgi?id=962168

Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>
Stephen Gordon 12 gadus atpakaļ
vecāks
revīzija
09d4be558d
1 mainītis faili ar 16 papildinājumiem un 10 dzēšanām
  1. 16
    10
      gitstats

+ 16
- 10
gitstats Parādīt failu

@@ -1348,10 +1348,21 @@ plot """
1348 1348
 </div>
1349 1349
 """)
1350 1350
 		
1351
+def usage():
1352
+	print """
1353
+Usage: gitstats [options] <gitpath..> <outputpath>
1354
+
1355
+Options:
1356
+-c key=value     Override configuration value
1357
+
1358
+Default config values:
1359
+%s
1360
+""" % conf
1361
+
1351 1362
 
1352 1363
 class GitStats:
1353 1364
 	def run(self, args_orig):
1354
-		optlist, args = getopt.getopt(args_orig, 'c:')
1365
+		optlist, args = getopt.getopt(args_orig, 'hc:', ["help"])
1355 1366
 		for o,v in optlist:
1356 1367
 			if o == '-c':
1357 1368
 				key, value = v.split('=', 1)
@@ -1364,17 +1375,12 @@ class GitStats:
1364 1375
 					conf[key][kk] = vv
1365 1376
 				else:
1366 1377
 					conf[key] = value
1378
+			elif o in ('-h', '--help'):
1379
+				usage()
1380
+				sys.exit()
1367 1381
 
1368 1382
 		if len(args) < 2:
1369
-			print """
1370
-Usage: gitstats [options] <gitpath..> <outputpath>
1371
-
1372
-Options:
1373
--c key=value     Override configuration value
1374
-
1375
-Default config values:
1376
-%s
1377
-""" % conf
1383
+			usage()
1378 1384
 			sys.exit(0)
1379 1385
 
1380 1386
 		outputpath = os.path.abspath(args[-1])