Skip to content

Commit 73ed435

Browse files
Slitting out the generation of the argument parser for the CLI
The generation of the argument parser is now a seperate function from calling it. This allows downstream programs to add extra functionality to their argument parser if needed.
1 parent 371e2d7 commit 73ed435

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

  • src/labthings_fastapi/server

src/labthings_fastapi/server/cli.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
from . import ThingServer, server_from_config
1111

12+
def get_default_parser():
13+
"""Return the default CLI parser for LabThings
14+
15+
This can be used instead of `parse_args` if more arguments are needed
16+
"""
1217

13-
def parse_args(argv: Optional[list[str]] = None) -> Namespace:
14-
"""Process command line arguments for the server"""
1518
parser = ArgumentParser()
1619
parser.add_argument("-c", "--config", type=str, help="Path to configuration file")
1720
parser.add_argument("-j", "--json", type=str, help="Configuration as JSON string")
@@ -29,9 +32,12 @@ def parse_args(argv: Optional[list[str]] = None) -> Namespace:
2932
default=5000,
3033
help="Bind socket to this port. If 0, an available port will be picked.",
3134
)
32-
args = parser.parse_args(argv)
33-
return args
35+
return parser
3436

37+
def parse_args(argv: Optional[list[str]] = None) -> Namespace:
38+
"""Process command line arguments for the server"""
39+
parser = get_default_parser()
40+
return parser.parse_args(argv)
3541

3642
def config_from_args(args: Namespace) -> dict:
3743
"""Process arguments and return a config dictionary"""

0 commit comments

Comments
 (0)