Skip to content

Commit 0bee26b

Browse files
committed
Added command line arguments to main.py
Specifically so that the port could be passed to the server
1 parent a5d30a6 commit 0bee26b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

main.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#!/usr/bin/env python3
2+
import sys
3+
import getopt
24
from murder import init_db, init_server
35

6+
# Get command line arguments
7+
optlist, args = getopt.getopt(sys.argv[1:], 'p', ['port='])
8+
opts = {key.lstrip('-'): value for (key, value) in optlist}
9+
if 'port' in opts:
10+
opts['port'] = int(opts['port'])
11+
412
# Initialise the database
513
init_db()
614

715
# Initialise the web server
8-
init_server().run()
16+
init_server(**opts).run()

murder/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def init_db(database=None):
2828
log.info("Error creating tables: {}".format(e))
2929

3030

31-
def init_server():
32-
server = Server()
31+
def init_server(**kwargs):
32+
server = Server(**kwargs)
3333

3434
# API pages
3535
server.register('/game', game)

0 commit comments

Comments
 (0)