def get_parser()

in cc_net/jsonql.py [0:0]


def get_parser():
    parser = argparse.ArgumentParser(
        description="Read a set of json files and allow to query them"
    )
    subparsers = parser.add_subparsers()

    def add_subparser(function, arguments):
        doc = function.__doc__.split("\n")[0]
        p = subparsers.add_parser(function.__name__, help=doc, parents=[io_parser()])
        p.set_defaults(command=function)
        for k, v in arguments.items():
            p.add_argument(k, **v)

    add_subparser(
        select,
        {
            "columns": dict(nargs="+", help="Extract the value of the given fields"),
            "--skip_empty": dict(
                action="store_true", help="Skip lines without the requested fields"
            ),
            "--separator": dict(
                default="\t", help="Separator to use between the different columns"
            ),
            "--newline": dict(
                default=NEWLINE,
                help="Replace newlines found in the text by the given string",
            ),
        },
    )

    add_subparser(
        where,
        {
            "clauses": dict(nargs="+", help=""),
            "--requires": dict(
                action="append", help="Python module required by the clauses code."
            ),
        },
    )

    add_subparser(
        merge,
        {
            "columns": dict(nargs="+", help=""),
            "--separator": dict(
                default="\t", help="Separator to use between the different columns"
            ),
            "--newline": dict(
                default=NEWLINE, help="Replace the given string by actual newlines"
            ),
        },
    )

    add_subparser(
        describe,
        {
            "columns": dict(nargs="*", help=""),
            "--bins": dict(
                default="auto", help="Number of bins for computing the histograms"
            ),
            "--cumulative": dict(
                action="store_true", help="Compute cumulative histograms"
            ),
            "--weights": dict(type=str, help="Column used to weight histograms"),
        },
    )

    add_subparser(split, {"--pattern": dict(type=str)})
    add_subparser(shard, {})
    return parser