aboutsummaryrefslogtreecommitdiff
path: root/repo.py
blob: 1a127ae47b974da8ca1fcd97f2aaf764a254bc47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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()