Completed
Pull Request — master (#1941)
by Abdeali
01:40
created

coalib.main()   B

Complexity

Conditions 5

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 5
dl 0
loc 32
rs 8.0894
1
# This program is free software: you can redistribute it and/or modify it
2
# under the terms of the GNU Affero General Public License as published by the
3
# Free Software Foundation, either version 3 of the License, or (at your
4
# option) any later version.
5
#
6
# This program is distributed in the hope that it will be useful, but WITHOUT
7
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
9
# for more details.
10
#
11
# You should have received a copy of the GNU Affero General Public License
12
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
13
14
import functools
15
16
from pyprint.ConsolePrinter import ConsolePrinter
17
18
from coalib.coala_main import run_coala
19
from coalib.collecting.Collectors import collect_all_bears_from_sections
20
from coalib.output.ConsoleInteraction import (
21
    acquire_settings, nothing_done, print_results, print_section_beginning,
22
    show_bears)
23
from coalib.output.printers.LogPrinter import LogPrinter
24
from coalib.parsing.DefaultArgParser import default_arg_parser
25
from coalib.settings.ConfigurationGathering import load_configuration
26
from coalib.settings.SectionFilling import fill_settings
27
28
29
def main():
30
    # Note: We parse the args here once to check whether to show bears or not.
31
    arg_parser = default_arg_parser()
32
    args = arg_parser.parse_args()
33
34
    console_printer = ConsolePrinter()
35
    if args.show_bears or args.show_all_bears:
36
        log_printer = LogPrinter(console_printer)
37
        sections, _ = load_configuration(arg_list=None, log_printer=log_printer)
38
        if args.show_all_bears:
39
            local_bears, global_bears = collect_all_bears_from_sections(
40
                sections, log_printer)
41
        else:
42
            # We ignore missing settings as it's not important.
43
            local_bears, global_bears = fill_settings(
44
                sections,
45
                acquire_settings=lambda *args, **kwargs: {},
46
                log_printer=log_printer)
47
        show_bears(local_bears, global_bears, args.show_all_bears,
48
                   console_printer)
49
        return 0
50
51
    partial_print_sec_beg = functools.partial(
52
        print_section_beginning,
53
        console_printer)
54
    results, exitcode, _ = run_coala(
55
        print_results=print_results,
56
        acquire_settings=acquire_settings,
57
        print_section_beginning=partial_print_sec_beg,
58
        nothing_done=nothing_done)
59
60
    return exitcode
61