27
27
28
28
from __future__ import annotations
29
29
30
+ from argparse import ArgumentParser
30
31
import logging
31
32
import os
32
33
import signal
@@ -49,12 +50,20 @@ class Main:
49
50
:ivar args: list of positional parameters after processing options
50
51
"""
51
52
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
+ ):
53
59
"""Initialize Main object.
54
60
55
61
:param name: name of the program (if not specified the filename without
56
62
extension is taken)
57
63
: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)
58
67
"""
59
68
# On UNIX set a signal handler for SIGTERM that will raise SystemExit
60
69
# 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):
68
77
else :
69
78
self .name = os .path .splitext (os .path .basename (main .__file__ ))[0 ]
70
79
71
- from argparse import ArgumentParser
72
-
73
- argument_parser = ArgumentParser ()
80
+ if argument_parser is None :
81
+ argument_parser = ArgumentParser ()
74
82
75
83
log_group = argument_parser .add_argument_group (title = "Logging arguments" )
76
84
log_group .add_argument (
0 commit comments