Fix usability around CLI

The cli is super straightforward, with just a single argument. But, that
doesn't mean people won't forget the config file or specify extra args
by mistake. This commit adds a --help/-h flag which will print the usage
information. It also will handle the case when an incorrect number of
arguments are supplied and refer the user to --help.
This commit is contained in:
Matthew Treinish 2017-04-03 22:59:11 -04:00
parent 80852893a5
commit 4a5adf8cca
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
1 changed files with 6 additions and 0 deletions

View File

@ -69,6 +69,12 @@ class MQTTStat(threading.Thread):
def main():
conf = None
if len(sys.argv) != 2:
print("Incorrect number of arguments, see --help")
sys.exit(1)
if sys.argv[1] == '--help' or sys.argv[1] == '-h':
print("usage: mqtt_statsd <config file>")
sys.exit(0)
with open(sys.argv[1], 'r') as conf_file:
conf = yaml.load(conf_file.read())
if not conf: