Completed
Pull Request — master (#1569)
by Lasse
01:37
created

coalib.main()   A

Complexity

Conditions 3

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 22
rs 9.2
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 json
15
16
from coalib.coala_main import run_coala
17
from coalib.output.JSONEncoder import JSONEncoder
18
from coalib.output.printers.ListLogPrinter import ListLogPrinter
19
from coalib.parsing.DefaultArgParser import default_arg_parser
20
21
22
def main():
23
    # Note: We parse the args here once to find the log printer to use.
24
    #       Also, commands like -h (help) and -v (version) are executed here.
25
    #       The args are again parsed later to find the settings and configs
26
    #       to use during analysis.
27
    arg_parser = default_arg_parser()
28
    args = arg_parser.parse_args()
29
30
    log_printer = None if args.text_logs else ListLogPrinter()
31
    results, exitcode = run_coala(log_printer=log_printer, autoapply=False)
32
33
    retval = {"results": results}
34
    if not args.text_logs:
35
        retval["logs"] = log_printer.logs
36
37
    print(json.dumps(retval,
38
                     cls=JSONEncoder,
39
                     sort_keys=True,
40
                     indent=2,
41
                     separators=(',', ': ')))
42
43
    return exitcode
44