diff options
-rwxr-xr-x | repo.py | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -0,0 +1,45 @@ +#!/usr/bin/python3 + +import requests +import argparse +import subprocess + +gitweb_url = "https://git.marks.kitchen" + +def list_repos(args): + r = requests.get(f"{gitweb_url}/repos.cgi") + for line in r.text.splitlines(): + title, remote, desc = line.split(",", 2) + print(title) + print("\t", desc) + print("\t", remote) + +def clone_repo(args): + r = requests.get(f"{gitweb_url}/repos.cgi") + for line in r.text.splitlines(): + title, remote, _ = line.split(",", 2) + if title == args["repo"]: + subprocess.run(["git", "clone", remote]) + +def main(): + parser = argparse.ArgumentParser("wikijscmd") + parser.set_defaults(command=None) + subparsers = parser.add_subparsers() + + parser_list = subparsers.add_parser("list", help="list repos") + parser_list.set_defaults(command=list_repos) + + parser_clone = subparsers.add_parser("clone", help="clone a repo") + parser_clone.add_argument("repo", type=str, help="repo name") + parser_clone.set_defaults(command=clone_repo) + + args = vars(parser.parse_args()) + callback = args["command"] + if callback is None: + parser.print_help() + else: + del args["command"] + callback(args) + +if __name__ == "__main__": + main() |