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)