Failed Conditions
Pull Request — master (#1569)
by Abdeali
01:55
created

coalib/coala_json.py (1 issue)

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