Passed
Push — main ( ddff4b...7b3fbc )
by Douglas
04:33
created

mandos.cli.Commands.build_taxonomy()   B

Complexity

Conditions 6

Size

Total Lines 46
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 26
nop 2
dl 0
loc 46
rs 8.3226
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A mandos.cli.MandosCli.init() 0 5 1
1
"""
2
Command-line interface for mandos.
3
"""
4
5
from __future__ import annotations
6
7
from typing import Type
8
9
import typer
0 ignored issues
show
introduced by
Unable to import 'typer'
Loading history...
10
from typer.models import CommandInfo
0 ignored issues
show
introduced by
Unable to import 'typer.models'
Loading history...
11
12
from mandos import logger, MandosLogging
13
from mandos.model.settings import MANDOS_SETTINGS
14
from mandos.entries.entries import Entries
15
from mandos.entries.api_singletons import Apis
16
from mandos.commands import MiscCommands
17
18
cli = typer.Typer()
19
20
21
class SearchCommands:
22
    """
23
    Entry points for mandos.
24
    """
25
26
27
def _init_commands():
28
    # Oh dear this is a nightmare
29
    # it's really hard to create typer commands with dynamically configured params --
30
    # we really need to rely on its inferring of params
31
    # that makes this really hard to do well
32
    for entry in Entries:
33
        info = CommandInfo(entry.cmd(), callback=entry.run)
34
        cli.registered_commands.append(info)
35
        # print(f"Registered {entry.cmd()} to {entry}")
36
        setattr(SearchCommands, entry.cmd(), entry.run)
37
38
    cli.registered_commands.extend(
39
        [
40
            CommandInfo(":search", callback=MiscCommands.search),
41
            CommandInfo(":export:taxa", callback=MiscCommands.build_taxonomy),
42
            CommandInfo(":tax:dl", callback=MiscCommands.dl_tax, hidden=True),
43
            CommandInfo(":cache", callback=MiscCommands.find),
44
            CommandInfo(":concat", callback=MiscCommands.concat),
45
            CommandInfo(":filter", callback=MiscCommands.filter),
46
            CommandInfo(":filter:taxa", callback=MiscCommands.filter_taxa),
47
            CommandInfo(":export:copy", callback=MiscCommands.copy),
48
            CommandInfo(":export:state", callback=MiscCommands.state),
49
            CommandInfo(":export:reify", callback=MiscCommands.reify),
50
            CommandInfo(":calc:scores", callback=MiscCommands.score),
51
            CommandInfo(":calc:matrix", callback=MiscCommands.matrix),
52
            CommandInfo(":calc:concordance", callback=MiscCommands.concordance),
53
        ]
54
    )
55
56
57
_init_commands()
58
59
60
class MandosCli:
61
    """
62
    Global entry point for various stuff. For import by consumers.
63
    """
64
65
    settings = MANDOS_SETTINGS
66
    logger = logger
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable logger does not seem to be defined.
Loading history...
67
    logging = MandosLogging
68
    main = cli
69
    search_cmds = SearchCommands
70
    misc_cmds = MiscCommands
71
72
    @classmethod
73
    def init(cls) -> Type[MandosCli]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
74
        MandosLogging.init()
75
        Apis.set_default()
76
        return cls
77
78
79
if __name__ == "__main__":
80
    MandosCli.init().main()
81
82
83
__all__ = ["MandosCli"]
84