summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozlog/mozlog/scripts/__init__.py
blob: f1392507f8e17d3113d366c9863565af94fcb5f9 (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
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


import argparse

import format as formatlog
import logmerge
import six
import unstable


def get_parser():
    parser = argparse.ArgumentParser(
        "structlog", description="Tools for dealing with structured logs"
    )

    commands = {
        "unstable": (unstable.get_parser, unstable.main),
        "format": (formatlog.get_parser, formatlog.main),
        "logmerge": (logmerge.get_parser, logmerge.main),
    }

    sub_parser = parser.add_subparsers(title="Subcommands")

    for command, (parser_func, main_func) in six.iteritems(commands):
        parent = parser_func(False)
        command_parser = sub_parser.add_parser(
            command, description=parent.description, parents=[parent]
        )
        command_parser.set_defaults(func=main_func)

    return parser


def main():
    parser = get_parser()
    args = parser.parse_args()
    args.func(**vars(args))