weitersager.cli.main()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.512

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 0
dl 0
loc 6
ccs 1
cts 5
cp 0.2
crap 1.512
rs 10
c 0
b 0
f 0
1
"""
2
weitersager.cli
3
~~~~~~~~~~~~~~~
4
5
Command line entry point
6
7
:Copyright: 2007-2025 Jochen Kupperschmidt
8
:License: MIT, see LICENSE for details.
9
"""
10
11 1
from __future__ import annotations
12 1
from argparse import ArgumentParser, Namespace
13 1
import importlib.metadata
14 1
from pathlib import Path
15 1
import sys
16
17 1
from .config import load_config
18 1
from .processor import start
19 1
from .util import configure_logging
20
21
22 1
def parse_args(args: list[str]) -> Namespace:
23
    """Parse command line arguments."""
24 1
    version = importlib.metadata.version('weitersager')
25
26 1
    parser = ArgumentParser()
27 1
    parser.add_argument(
28
        '--version', action='version', version=f'Weitersager {version}'
29
    )
30 1
    parser.add_argument('config_filename', type=Path)
31 1
    return parser.parse_args(args)
32
33
34 1
def main() -> None:
35
    """Load the configuration file, start the IRC bot and HTTP listen server."""
36
    namespace = parse_args(sys.argv[1:])
37
    config = load_config(namespace.config_filename)
38
    configure_logging(config.log_level)
39
    start(config)
40
41
42 1
if __name__ == '__main__':
43
    main()
44