Update README and main.py to support bible-only mode and improve command formatting

This commit is contained in:
Kyler Olsen 2025-04-28 17:37:40 -06:00
parent b2f4f69937
commit a4d7279c22
3 changed files with 16 additions and 10 deletions

View File

@ -10,24 +10,25 @@
Python 3.10 or greater is recommended.
In the root of the repo run this command.
```pip install -r requirements.txt```
In the root of the repo run this command to install the required python modules.
```$ pip install -r requirements.txt```
## Running
The following command with run the server.
The following command to run the server.
```python3 main.py -s```
```$ python3 main.py -s```
The following command with run the client.
The following command to run the client.
```python3 main.py```
```$ python3 main.py```
Here are the options for running.
```
$ python3 main.py -h
usage: main.py [-h] [-s] [-H HOST] [-p PORT] [-n PLAYERNAME]
usage: main.py [-h] [-s] [-H HOST] [-p PORT] [-n PLAYERNAME] [-b]
Run the server or client.
@ -38,4 +39,5 @@ options:
-p PORT, --port PORT Port number (default: 7788)
-n PLAYERNAME, --playername PLAYERNAME
Player name (for client)
-b, --bible-only Run in bible-only mode (for server)
```

View File

@ -35,6 +35,7 @@ class Library:
def serve_forever(self):
try:
print(f"Starting server at {self.__host}:{self.__port}")
if self.__bible_only: print("Bible-only mode active.")
with self.__socket as s:
s.bind((self.__host, self.__port))
s.listen(1)

View File

@ -47,9 +47,9 @@ def name_gen():
return random.choice(adjectives).capitalize() + random.choice(animals).capitalize()
def server(host: str='', port: int=7788):
def server(host: str='', port: int=7788, bible_only: bool=False):
from library import Library
lib = Library(host, port)
lib = Library(host, port, bible_only=bible_only)
lib.serve_forever()
def client(playername: str = "", host: str='localhost', port: int=7788):
@ -72,10 +72,13 @@ def main(argv):
parser.add_argument(
"-n", "--playername", type=str, default="", help="Player name (for client)"
)
parser.add_argument(
"-b", "--bible-only", action="store_true", help="Run in bible-only mode (for server)"
)
args = parser.parse_args(argv[1:])
if args.server:
server(host=args.host, port=args.port)
server(host=args.host, port=args.port, bible_only=args.bible_only)
else:
client(playername=args.playername, host=args.host or 'localhost', port=args.port)