Skip to content

Commit 086649d

Browse files
authored
Merge pull request #399 from manthonyaiello/feature/T622-026
Make ArgumentParser an optional parameter to Main
2 parents 89a089b + e281c80 commit 086649d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/e3/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from __future__ import annotations
2929

30+
from argparse import ArgumentParser
3031
import logging
3132
import os
3233
import signal
@@ -49,12 +50,20 @@ class Main:
4950
:ivar args: list of positional parameters after processing options
5051
"""
5152

52-
def __init__(self, name: Optional[str] = None, platform_args: bool = False):
53+
def __init__(
54+
self,
55+
name: Optional[str] = None,
56+
platform_args: bool = False,
57+
argument_parser: Optional[ArgumentParser] = None,
58+
):
5359
"""Initialize Main object.
5460
5561
:param name: name of the program (if not specified the filename without
5662
extension is taken)
5763
:param platform_args: add --build, --host, --target support
64+
:param argument_parser: the ArgumentParser to use for parsing
65+
command-line arguments (if not specified, an ArgumentParser will be
66+
created by Main)
5867
"""
5968
# On UNIX set a signal handler for SIGTERM that will raise SystemExit
6069
# This is to let an e3 application enough time to perform
@@ -68,9 +77,8 @@ def __init__(self, name: Optional[str] = None, platform_args: bool = False):
6877
else:
6978
self.name = os.path.splitext(os.path.basename(main.__file__))[0]
7079

71-
from argparse import ArgumentParser
72-
73-
argument_parser = ArgumentParser()
80+
if argument_parser is None:
81+
argument_parser = ArgumentParser()
7482

7583
log_group = argument_parser.add_argument_group(title="Logging arguments")
7684
log_group.add_argument(

0 commit comments

Comments
 (0)