From 6191182cb30034094de60f04c309125e4f9ff68c Mon Sep 17 00:00:00 2001 From: Matt Skone Date: Thu, 28 May 2015 15:28:44 -0700 Subject: [PATCH] Support optional command-line argument specifying full path to conf file. --- rtmbot.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rtmbot.py b/rtmbot.py index bc0669c..3bd4184 100755 --- a/rtmbot.py +++ b/rtmbot.py @@ -10,6 +10,7 @@ import os import sys import time import logging +from argparse import ArgumentParser from slackclient import SlackClient @@ -164,14 +165,27 @@ def main_loop(): except: logging.exception('OOPS') + +def parse_args(): + parser = ArgumentParser() + parser.add_argument( + '-c', + '--config', + help='Full path to config file.', + metavar='path' + ) + return parser.parse_args() + + if __name__ == "__main__": + args = parse_args() directory = os.path.dirname(sys.argv[0]) if not directory.startswith('/'): directory = os.path.abspath("{}/{}".format(os.getcwd(), directory )) - config = yaml.load(file('rtmbot.conf', 'r')) + config = yaml.load(file(args.config or 'rtmbot.conf', 'r')) debug = config["DEBUG"] bot = RtmBot(config["SLACK_TOKEN"]) site_plugins = []