Correctly handle subcommand help

etherdump --help and etherdump CMD --help should work.
This commit is contained in:
Luke Murphy 2019-09-28 00:02:17 +02:00
parent 0f3edc0970
commit bc3f0bb703
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

View File

@ -52,16 +52,18 @@ try:
else: else:
args = sys.argv[2:] args = sys.argv[2:]
if any(arg in args for arg in ['--help', '-h']): if len(sys.argv) < 3:
print(usage) if any(arg in args for arg in ['--help', '-h']):
sys.exit(0) print(usage)
elif any(arg in args for arg in ['--version', '-v']): sys.exit(0)
print('etherpump {}'.format(__VERSION__)) elif any(arg in args for arg in ['--version', '-v']):
sys.exit(0) print('etherpump {}'.format(__VERSION__))
sys.exit(0)
except IndexError: except IndexError:
print(usage) print(usage)
sys.exit(0) sys.exit(0)
try: try:
# http://stackoverflow.com/questions/301134/dynamic-module-import-in-python # http://stackoverflow.com/questions/301134/dynamic-module-import-in-python
cmdmod = __import__( cmdmod = __import__(