From 4a5adf8ccadfc4aa20598d210b1d56f498c7510e Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 3 Apr 2017 22:59:11 -0400 Subject: [PATCH] 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. --- mqtt_statsd/daemon.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mqtt_statsd/daemon.py b/mqtt_statsd/daemon.py index f44a13f..cba9423 100644 --- a/mqtt_statsd/daemon.py +++ b/mqtt_statsd/daemon.py @@ -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 ") + sys.exit(0) with open(sys.argv[1], 'r') as conf_file: conf = yaml.load(conf_file.read()) if not conf: