Skip to content

Commit a19991b

Browse files
Merge pull request #105 from labthings/split-out-arg-parser
Splitting out the generation of the argument parser for the CLI
2 parents 30d7657 + 6884adb commit a19991b

File tree

1 file changed

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

1 file changed

+14
-4
lines changed

src/labthings_fastapi/server/cli.py

Lines changed: 14 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,14 @@ 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+
# Use parser to parse CLI arguments and return the namespace with attributes set.
43+
return parser.parse_args(argv)
3444

3545

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

0 commit comments

Comments
 (0)