File indexing completed on 2024-12-01 08:16:20
0001 """ 0002 Module containing login command 0003 """ 0004 0005 # SPDX-FileCopyrightText: 2020 Benjamin Port <benjamin.port@kde.org> 0006 # 0007 # SPDX-License-Identifier: GPL-2.0-or-later 0008 import argparse 0009 0010 from lab.config import Config 0011 0012 0013 def parser( 0014 subparsers: argparse._SubParsersAction, # pylint: disable=protected-access 0015 ) -> argparse.ArgumentParser: 0016 """ 0017 Subparser for login command 0018 :param subparsers: subparsers object from global parser 0019 :return: login subparser 0020 """ 0021 0022 login_parser: argparse.ArgumentParser = subparsers.add_parser( 0023 "login", help="Save a token for a GitLab instance" 0024 ) 0025 login_parser.add_argument("--host", help="GitLab host (e.g invent.kde.org)", required=True) 0026 0027 group = login_parser.add_mutually_exclusive_group(required=True) 0028 group.add_argument("--token", help="GitLab api private token") 0029 group.add_argument("--command", help="Command to run when a token is needed") 0030 0031 return login_parser 0032 0033 0034 def run(args: argparse.Namespace) -> None: 0035 """ 0036 run login command 0037 :param args: parsed arguments 0038 """ 0039 config: Config = Config() 0040 0041 if args.command: 0042 config.set_auth_command(args.host, args.command) 0043 else: 0044 config.set_token(args.host, args.token) 0045 0046 config.save()