1# This Source Code Form is subject to the terms of the Mozilla Public
2# License, v. 2.0. If a copy of the MPL was not distributed with this
3# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5import json
6
7from ..result import IssueEncoder
8from .compact import CompactFormatter
9from .stylish import StylishFormatter
10from .summary import SummaryFormatter
11from .treeherder import TreeherderFormatter
12from .unix import UnixFormatter
13
14
15class JSONFormatter(object):
16    def __call__(self, result):
17        return json.dumps(result.issues, cls=IssueEncoder)
18
19
20all_formatters = {
21    "compact": CompactFormatter,
22    "json": JSONFormatter,
23    "stylish": StylishFormatter,
24    "summary": SummaryFormatter,
25    "treeherder": TreeherderFormatter,
26    "unix": UnixFormatter,
27}
28
29
30def get(name, **fmtargs):
31    return all_formatters[name](**fmtargs)
32