Unverified Commit b66567e0 authored by Jonah Brüchert's avatar Jonah Brüchert
Browse files

Add rewrite-remote subcommand

parent a3b0acb3
......@@ -26,6 +26,7 @@ from lab import (
issues,
snippet,
workflow,
rewrite_remote
)
from lab.utils import Utils, LogType
......@@ -52,6 +53,7 @@ class Parser: # pylint: disable=R0903
issues,
snippet,
workflow,
rewrite_remote
]
for command in command_list:
parser = command.parser(self.subparsers)
......
"""
Module of the rewrite-remote subcommand
"""
# SPDX-FileCopyrightText: 2020 Jonah Brüchert <jbb@kaidan.im>
#
# SPDX-License-Identifier: GPL-2.0-or-later
import argparse
from git import Repo
from lab.utils import Utils
def parser(
subparsers: argparse._SubParsersAction, # pylint: disable=protected-access
) -> argparse.ArgumentParser:
rewrite_remote_parser: argparse.ArgumentParser = subparsers.add_parser(
"rewrite-remote", help="Rewrite the remote url to ssh"
)
rewrite_remote_parser.add_argument(
"remote",
type=str,
nargs=1,
help="Name of the remote to rewrite",
)
return rewrite_remote_parser
def run(args: argparse.Namespace) -> None:
repo: Repo = Utils.get_cwd_repo()
remote_url = repo.git.remote("get-url", args.remote)
ssh_url = Utils.ssh_url_from_http(Utils.normalize_url(remote_url))
repo.git.remote("set-url", args.remote, ssh_url)
......@@ -47,6 +47,7 @@ class TextFormatting: # pylint: disable=too-few-public-methods
underline: Final[str] = "\033[4m"
end: Final[str] = "\033[0m"
class Utils:
"""
This class contains static methods for common tasks
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment