From aa193c12981dbe9c04d7182b998fafd8aa84d273 Mon Sep 17 00:00:00 2001 From: dkvasov Date: Wed, 16 May 2018 17:30:52 +0300 Subject: [PATCH] zulip_botserver: Extract input parameters. --- .../zulip_botserver/input_parameters.py | 46 +++++++++++++++++++ zulip_botserver/zulip_botserver/server.py | 33 ------------- 2 files changed, 46 insertions(+), 33 deletions(-) create mode 100644 zulip_botserver/zulip_botserver/input_parameters.py diff --git a/zulip_botserver/zulip_botserver/input_parameters.py b/zulip_botserver/zulip_botserver/input_parameters.py new file mode 100644 index 0000000..134cdd3 --- /dev/null +++ b/zulip_botserver/zulip_botserver/input_parameters.py @@ -0,0 +1,46 @@ +import argparse + + +def parse_args() -> argparse.Namespace: + usage = ''' + zulip-bot-server --config-file --hostname
--port + Example1: zulip-bot-server --config-file ~/flaskbotrc + Example2: zulip-bot-server --config-file ~/flaskbotrc -b mybotname + (This program loads the bot configurations from the + config file (flaskbotrc here) and loads the bot modules. + It then starts the server and fetches the requests to the + above loaded modules and returns the success/failure result) + Please make sure you have a current flaskbotrc file with the + configurations of the required bots. + Hostname and Port are optional arguments. Default hostname is + 127.0.0.1 and default port is 5002. + See lib/readme.md for more context. + ''' + + parser = argparse.ArgumentParser(usage=usage) + parser.add_argument( + '--config-file', + action='store', + required=True, + help='Config file for the zulip bot server (flaskbotrc)' + ) + parser.add_argument( + '--bot-name', '-b', + action='store', + help='Bot name (optional, rewrites first bot name from config file). ' + 'Only for single-bot usage! Other bots will be ignored' + ) + parser.add_argument( + '--hostname', + action='store', + default="127.0.0.1", + help='Address on which you want to run the server' + ) + parser.add_argument( + '--port', + action='store', + default=5002, + type=int, + help='Port on which you want to run the server' + ) + return parser.parse_args() diff --git a/zulip_botserver/zulip_botserver/server.py b/zulip_botserver/zulip_botserver/server.py index fb62b71..14f6084 100644 --- a/zulip_botserver/zulip_botserver/server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -1,4 +1,3 @@ -import argparse import configparser import json import os @@ -105,38 +104,6 @@ def handle_bot(bot: str) -> Union[str, BadRequest]: return json.dumps("") -def parse_args() -> argparse.Namespace: - usage = ''' - zulip-bot-server --config-file --hostname
--port - Example: zulip-bot-server --config-file ~/flaskbotrc - (This program loads the bot configurations from the - config file (flaskbotrc here) and loads the bot modules. - It then starts the server and fetches the requests to the - above loaded modules and returns the success/failure result) - Please make sure you have a current flaskbotrc file with the - configurations of the required bots. - Hostname and Port are optional arguments. Default hostname is - 127.0.0.1 and default port is 5002. - See lib/readme.md for more context. - ''' - - parser = argparse.ArgumentParser(usage=usage) - parser.add_argument('--config-file', - action='store', - required=True, - help='Config file for the zulip bot server (flaskbotrc)') - parser.add_argument('--hostname', - action='store', - default="127.0.0.1", - help='Address on which you want to run the server') - parser.add_argument('--port', - action='store', - default=5002, - type=int, - help='Port on which you want to run the server') - return parser.parse_args() - - def main() -> None: options = parse_args() bots_config = read_config_file(options.config_file)