浏览代码

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 年前
父节点
当前提交
09d4be558d
共有 1 个文件被更改,包括 16 次插入10 次删除
  1. 16
    10
      gitstats

+ 16
- 10
gitstats 查看文件

1348
 </div>
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
 class GitStats:
1363
 class GitStats:
1353
 	def run(self, args_orig):
1364
 	def run(self, args_orig):
1354
-		optlist, args = getopt.getopt(args_orig, 'c:')
1365
+		optlist, args = getopt.getopt(args_orig, 'hc:', ["help"])
1355
 		for o,v in optlist:
1366
 		for o,v in optlist:
1356
 			if o == '-c':
1367
 			if o == '-c':
1357
 				key, value = v.split('=', 1)
1368
 				key, value = v.split('=', 1)
1364
 					conf[key][kk] = vv
1375
 					conf[key][kk] = vv
1365
 				else:
1376
 				else:
1366
 					conf[key] = value
1377
 					conf[key] = value
1378
+			elif o in ('-h', '--help'):
1379
+				usage()
1380
+				sys.exit()
1367
 
1381
 
1368
 		if len(args) < 2:
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
 			sys.exit(0)
1384
 			sys.exit(0)
1379
 
1385
 
1380
 		outputpath = os.path.abspath(args[-1])
1386
 		outputpath = os.path.abspath(args[-1])