Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa193c1

Browse files
committed
zulip_botserver: Extract input parameters.
1 parent f90913d commit aa193c1

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import argparse
2+
3+
4+
def parse_args() -> argparse.Namespace:
5+
usage = '''
6+
zulip-bot-server --config-file <path to flaskbotrc> --hostname <address> --port <port>
7+
Example1: zulip-bot-server --config-file ~/flaskbotrc
8+
Example2: zulip-bot-server --config-file ~/flaskbotrc -b mybotname
9+
(This program loads the bot configurations from the
10+
config file (flaskbotrc here) and loads the bot modules.
11+
It then starts the server and fetches the requests to the
12+
above loaded modules and returns the success/failure result)
13+
Please make sure you have a current flaskbotrc file with the
14+
configurations of the required bots.
15+
Hostname and Port are optional arguments. Default hostname is
16+
127.0.0.1 and default port is 5002.
17+
See lib/readme.md for more context.
18+
'''
19+
20+
parser = argparse.ArgumentParser(usage=usage)
21+
parser.add_argument(
22+
'--config-file',
23+
action='store',
24+
required=True,
25+
help='Config file for the zulip bot server (flaskbotrc)'
26+
)
27+
parser.add_argument(
28+
'--bot-name', '-b',
29+
action='store',
30+
help='Bot name (optional, rewrites first bot name from config file). '
31+
'Only for single-bot usage! Other bots will be ignored'
32+
)
33+
parser.add_argument(
34+
'--hostname',
35+
action='store',
36+
default="127.0.0.1",
37+
help='Address on which you want to run the server'
38+
)
39+
parser.add_argument(
40+
'--port',
41+
action='store',
42+
default=5002,
43+
type=int,
44+
help='Port on which you want to run the server'
45+
)
46+
return parser.parse_args()

zulip_botserver/zulip_botserver/server.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import argparse
21
import configparser
32
import json
43
import os
@@ -105,38 +104,6 @@ def handle_bot(bot: str) -> Union[str, BadRequest]:
105104
return json.dumps("")
106105

107106

108-
def parse_args() -> argparse.Namespace:
109-
usage = '''
110-
zulip-bot-server --config-file <path to flaskbotrc> --hostname <address> --port <port>
111-
Example: zulip-bot-server --config-file ~/flaskbotrc
112-
(This program loads the bot configurations from the
113-
config file (flaskbotrc here) and loads the bot modules.
114-
It then starts the server and fetches the requests to the
115-
above loaded modules and returns the success/failure result)
116-
Please make sure you have a current flaskbotrc file with the
117-
configurations of the required bots.
118-
Hostname and Port are optional arguments. Default hostname is
119-
127.0.0.1 and default port is 5002.
120-
See lib/readme.md for more context.
121-
'''
122-
123-
parser = argparse.ArgumentParser(usage=usage)
124-
parser.add_argument('--config-file',
125-
action='store',
126-
required=True,
127-
help='Config file for the zulip bot server (flaskbotrc)')
128-
parser.add_argument('--hostname',
129-
action='store',
130-
default="127.0.0.1",
131-
help='Address on which you want to run the server')
132-
parser.add_argument('--port',
133-
action='store',
134-
default=5002,
135-
type=int,
136-
help='Port on which you want to run the server')
137-
return parser.parse_args()
138-
139-
140107
def main() -> None:
141108
options = parse_args()
142109
bots_config = read_config_file(options.config_file)

0 commit comments

Comments
 (0)