Skip to content

Commit 1dfa84a

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 1dfa84a

File tree

1 file changed

+13
-4
lines changed
  • src/labthings_fastapi/server

1 file changed

+13
-4
lines changed

src/labthings_fastapi/server/cli.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
from . import ThingServer, server_from_config
1111

1212

13-
def parse_args(argv: Optional[list[str]] = None) -> Namespace:
14-
"""Process command line arguments for the server"""
13+
def get_default_parser():
14+
"""Return the default CLI parser for LabThings
15+
16+
This can be used instead of `parse_args` if more arguments are needed
17+
"""
18+
1519
parser = ArgumentParser()
1620
parser.add_argument("-c", "--config", type=str, help="Path to configuration file")
1721
parser.add_argument("-j", "--json", type=str, help="Configuration as JSON string")
@@ -29,8 +33,13 @@ def parse_args(argv: Optional[list[str]] = None) -> Namespace:
2933
default=5000,
3034
help="Bind socket to this port. If 0, an available port will be picked.",
3135
)
32-
args = parser.parse_args(argv)
33-
return args
36+
return parser
37+
38+
39+
def parse_args(argv: Optional[list[str]] = None) -> Namespace:
40+
"""Process command line arguments for the server"""
41+
parser = get_default_parser()
42+
return parser.parse_args(argv)
3443

3544

3645
def config_from_args(args: Namespace) -> dict:

0 commit comments

Comments
 (0)