-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargs_parser.py
More file actions
49 lines (37 loc) · 1.21 KB
/
Copy pathargs_parser.py
File metadata and controls
49 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Simple arguments parser"""
import argparse
from dataclasses import dataclass
from src.version import VERSION
@dataclass
class ArgumentData:
"""Holding the parsed arguments or its default values"""
# TODO: your args
# debug logging
debug: bool
def init_args_parser() -> argparse.ArgumentParser:
"""Initializes the argument parser
Returns:
argparse.ArgumentParser: Initialized argument parser
"""
parser = argparse.ArgumentParser(
prog=f"YOUR PROJECT v{VERSION}",
description="""
Your project description.
"""
)
# debug logging
parser.add_argument('--debug', required=False,
action='store_true', # on-off switch
help=argparse.SUPPRESS)
return parser
def try_get_args(parser: argparse.ArgumentParser) -> ArgumentData | None:
"""Tries to parse the defined arguments.
May print errors and return None.
Args:
parser (argparse.ArgumentParser): The initialized parser
Returns:
ArgumentData | None: Your defined argument data if successful
"""
args = parser.parse_args()
# TODO: check values and handle errors
return ArgumentData(bool(args.debug))