Passed
Push — dependabot/pip/pyarrow-4.0.1 ( ca09ce...b2836e )
by
unknown
02:18 queued 20s
created

mandos.cli.MandosCli.init()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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 MandosLogging, logger
13
from mandos.commands import MiscCommands
14
from mandos.entries.api_singletons import Apis
15
from mandos.entries.entries import Entries
16
from mandos.model.settings import MANDOS_SETTINGS
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 += [
39
        CommandInfo(":search", callback=MiscCommands.search),
40
        CommandInfo(":export:tax-tree", callback=MiscCommands.build_taxonomy),
41
        CommandInfo(":tax:dl", callback=MiscCommands.dl_tax, hidden=True),
42
        CommandInfo(":cache", callback=MiscCommands.find),
43
        CommandInfo(":concat", callback=MiscCommands.concat),
44
        CommandInfo(":filter", callback=MiscCommands.filter),
45
        CommandInfo(":filter:taxa", callback=MiscCommands.filter_taxa),
46
        CommandInfo(":export:copy", callback=MiscCommands.copy),
47
        CommandInfo(":export:state", callback=MiscCommands.state),
48
        CommandInfo(":export:reify", callback=MiscCommands.reify),
49
        CommandInfo(":export:db", callback=MiscCommands.deposit),
50
        CommandInfo(":serve", callback=MiscCommands.serve),
51
        CommandInfo(":calc:scores", callback=MiscCommands.score),
52
        CommandInfo(":calc:matrix", callback=MiscCommands.matrix),
53
        CommandInfo(":calc:matrix-concordance", callback=MiscCommands.concordance),
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