#!/usr/bin/python3
# pylint: disable=invalid-name  # https://github.com/PyCQA/pylint/issues/516
import logging

import argcomplete.completers

import mini_buildd.cli
import mini_buildd.changes

LOG = logging.getLogger("mini_buildd")

#: Needed for man page hack in setup.py
DESCRIPTION = "Upload it like mini-buildd (unlike dput/dput-ng, supports ftps)"


class CLI(mini_buildd.cli.CLI):
    def __init__(self):
        self.dputcf = mini_buildd.cli.DputCf()

        super().__init__("mini-buildd-dput", DESCRIPTION)
        self.parser.add_argument("-f", "--force", action="store_true", help="Disable check for unique upload")
        self.parser.add_argument("target", action="store", metavar="TARGET",
                                 help=f"dput target (configuration section id in .dput.cf)").completer = self.dputcf.target_completer
        self.parser.add_argument("changes", action="store", metavar="CHANGES",
                                 help=f"changes file").completer = argcomplete.completers.FilesCompleter([".changes"])

    def runcli(self):
        changes = mini_buildd.changes.Changes(self.args.changes)
        endpoint = mini_buildd.net.ClientEndpoint(self.dputcf.get_target_ftp_url(self.args.target))
        changes.upload_retry_tls(endpoint, force=self.args.force)


CLI().run()
