summaryrefslogtreecommitdiff
path: root/bin/qmk
blob: 47b50f83b3bc467349632e6c68bd80f29c44a06f (plain)
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
#!/usr/bin/env python3
"""CLI wrapper for running QMK commands.
"""
import os
import sys
from pathlib import Path

# Add the QMK python libs to our path
script_dir = Path(os.path.realpath(__file__)).parent
qmk_dir = script_dir.parent
python_lib_dir = Path(qmk_dir / 'lib' / 'python').resolve()
sys.path.append(str(python_lib_dir))

# Setup the CLI
import milc  # noqa

milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}Ψ{style_reset_all}'


@milc.cli.entrypoint('QMK Helper Script')
def qmk_main(cli):
    """The function that gets run when no subcommand is provided.
    """
    cli.print_help()


def main():
    """Setup our environment and then call the CLI entrypoint.
    """
    # Change to the root of our checkout
    os.environ['ORIG_CWD'] = os.getcwd()
    os.chdir(qmk_dir)

    # Import the subcommands
    import qmk.cli  # noqa

    # Execute
    return_code = milc.cli()

    if return_code is False:
        exit(1)

    elif return_code is not True and isinstance(return_code, int):
        if return_code < 0 or return_code > 255:
            milc.cli.log.error('Invalid return_code: %d', return_code)
            exit(255)

        exit(return_code)

    exit(0)


if __name__ == '__main__':
    main()