-
Notifications
You must be signed in to change notification settings - Fork 0
/
exit_codes.py
66 lines (44 loc) · 1.31 KB
/
exit_codes.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import enum
import logging
import sys
import typing as T
class ExitCode(enum.IntEnum):
"""Exit status codes."""
# Internal error
PROGRAMMING_ERROR = 1
# 2 is used by argparse
# Input errors
TOOLS_DIR_NOT_FOUND = 3
TOOLS_NOT_FOUND = 4
TARGET_DIR_NOT_FOUND = 5
COMPILE_COMMAND_FILE_ERROR = 6
NO_SUPPORTED_FILES_FOUND = 7
WRONG_FILES = 8
# Errors related to tools
TOKEI_TOOL_ERR = 9
RUST_CODE_ANALYSIS_TOOL_ERR = 10
CCCC_TOOL_ERR = 11
MI_TOOL_ERR = 12
HALSTEAD_TOOL_ERR = 13
# Errors related to metrics
METRIC_NOT_FOUND = 14
DIFFERENT_METRIC_VALUE = 15
def log_conf(verbose: bool) -> None:
"""Configure logging."""
if verbose:
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
else:
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
def log_debug(msg: str, *args: T.Any) -> None:
"""Log debug."""
logging.debug(msg.format(*args))
def log_info(msg: str, *args: T.Any) -> None:
"""Log info."""
logging.info(msg.format(*args))
def log_warn(msg: str, *args: T.Any) -> None:
"""Log warning."""
logging.warning(msg.format(*args))
def log_err(msg: str, error: ExitCode, *args: T.Any) -> None:
"""Log error."""
logging.error(msg.format(*args))
sys.exit(error.value)