diff --git a/github-list-repos b/github-list-repos index 6bf01c2..7953290 100755 --- a/github-list-repos +++ b/github-list-repos @@ -10,19 +10,16 @@ import time GIT_URLS_OPTION = '--git-urls' GITGUD_COMPLETE_ITEMS_OPTION = '--gitgud-complete-items' -MODES = (GIT_URLS_OPTION, GITGUD_COMPLETE_ITEMS_OPTION) +NAME_OPTION = '--name' +MODES = (GIT_URLS_OPTION, GITGUD_COMPLETE_ITEMS_OPTION, NAME_OPTION) mode = None -name = False users = sys.argv[1:] -if users and users[0] == '--name': - name = True - users = users[1:] if users and users[0] in MODES: mode = users[0] users = users[1:] -assert users and (mode is None or mode in MODES) and not users[0].startswith('--'), f'Usage: github-list-repos [--name] [{" | ".join(MODES)}] USER [USER...]' +assert users and (mode is None or mode in MODES) and not users[0].startswith('--'), f'Usage: github-list-repos [{" | ".join(MODES)}] USER [USER...]' def get(url): @@ -51,7 +48,7 @@ for user in users: r = get(f'https://github.com/{user}') if '
', r.text) if not musername: print('Error: could not find profile:username meta tag', file = sys.stderr) @@ -62,6 +59,7 @@ for user in users: sys.exit(1) print(html.unescape(musername.group(1).strip().replace('\n', ' ').replace('\r', ' '))) print(html.unescape(mfullname.group(1).strip().replace('\n', ' ').replace('\r', ' '))) + sys.exit(0) r = get(f'https://github.com/orgs/{user}/repositories') page = 1 while True: @@ -74,7 +72,7 @@ for user in users: r = get(f'https://github.com/orgs/{user}/repositories?page={page}') else: # User, ?tab=repositories + cursor pagination - if name: + if mode == NAME_OPTION: musername = re.search(r']*\s)?class="(?:[^"]*\s)?vcard-username(?:\s[^"]*)?"(?:\s[^>]*)?>(.*?)', r.text, flags = re.DOTALL) if not musername: print('Error: could not find vcard-username span', file = sys.stderr) @@ -85,6 +83,7 @@ for user in users: fullname = '' print(html.unescape(musername.group(1).strip()).replace('\n', ' ').replace('\r', ' ')) print(fullname.replace('\n', ' ').replace('\r', ' ')) + sys.exit(0) r = get(f'https://github.com/{user}?tab=repositories') while True: for m in re.finditer(r'"]+)" itemprop="name codeRepository"(\s[^>]*)?>', r.text):