Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/labthings_fastapi/server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
from . import ThingServer, server_from_config


def parse_args(argv: Optional[list[str]] = None) -> Namespace:
"""Process command line arguments for the server"""
def get_default_parser():
"""Return the default CLI parser for LabThings

This can be used instead of `parse_args` if more arguments are needed
"""

parser = ArgumentParser()
parser.add_argument("-c", "--config", type=str, help="Path to configuration file")
parser.add_argument("-j", "--json", type=str, help="Configuration as JSON string")
Expand All @@ -29,8 +33,14 @@
default=5000,
help="Bind socket to this port. If 0, an available port will be picked.",
)
args = parser.parse_args(argv)
return args
return parser


def parse_args(argv: Optional[list[str]] = None) -> Namespace:
"""Process command line arguments for the server"""
parser = get_default_parser()
# Use parser to parse CLI arguments and return the namespace with attributes set.
return parser.parse_args(argv)


def config_from_args(args: Namespace) -> dict:
Expand Down Expand Up @@ -61,7 +71,7 @@
server = server_from_config(config)
assert isinstance(server, ThingServer)
if dry_run:
return server

Check warning on line 74 in src/labthings_fastapi/server/cli.py

View workflow job for this annotation

GitHub Actions / coverage

74 line is not covered with tests
uvicorn.run(server.app, host=args.host, port=args.port)
except BaseException as e:
if args.fallback:
Expand Down