#!/usr/bin/env python

# oio-rdir-crawler
# Copyright (C) 2021-2024 OVH SAS
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from oio.common.green import eventlet_monkey_patch

eventlet_monkey_patch()

import argparse
from oio.crawler.rdir import RdirCrawler
from oio.common.daemon import run_daemon


def make_arg_parser():
    descr = RdirCrawler.__doc__
    parser = argparse.ArgumentParser(description=descr)
    parser.add_argument(
        "config",
        help="""
        A file containing an oio-rdir-crawler configuration file.
        Any arguments passed alongside a configuration file will be ignored.
        """,
    )
    parser.add_argument(
        "--verbose", "-v", action="store_true", help="More verbose output"
    )
    return parser


if __name__ == "__main__":
    args = make_arg_parser().parse_args()
    verbose = args.verbose
    config = args.config

    run_daemon(
        RdirCrawler, conf_file=config, section_name="rdir-crawler", verbose=verbose
    )
