Skip to content
Snippets Groups Projects
Commit 46cfbfe3 authored by Karl Fogel's avatar Karl Fogel
Browse files

Improve option parsing

parent ecafcf1c
No related branches found
No related tags found
No related merge requests found
......@@ -7,9 +7,11 @@ entities (issues, labels, milestones, etc) in a GitLab project.
Usage
$ ./gl-sak --root OWNER[/PROJECT_PATH] COMMAND [ARGS...]
$ ./gl-sak --gitlab=GL_SERVER --user USER [--root PROJECT_PATH] COMMAND [ARGS...]
OWNER/PROJECT_PATH is something like "jrandom/foo/bar/myproj".
E.g.,
$ ./gl-sak --user jrandom --gitlab=https://code.librehq.com --root foo/bar/myproj baz qux quux
TBD: Document some commands, some of which take further arguments.
......@@ -76,26 +78,39 @@ def main():
# here would be RawDescriptionHelpFormatter.
formatter_class=argparse.RawTextHelpFormatter)
arg_parser.add_argument(
'--gitlab',
help="The URL of the GitLab server (not with path appended)")
arg_parser.add_argument(
'--root',
help="The root path of the project to operate on")
arg_parser.add_argument(
'--user',
help="The username to log in to GitLab with")
authn_token_arg = arg_parser.add_mutually_exclusive_group()
authn_token_arg.add_argument(
'-T', '--authn-token',
# TBD: This next one is not implemented yet. Also, how to
# tell argparse that two options are mutually incompatible?
# Do we just have to do that with post-parsing code, or does
# argparse have a built-in way to handle it?
'-F', '--authn-token-file',
help="The GitLab access token to use for this operation")
authn_token_arg.add_argument(
'-F', '--authn-token-file',
help="File containing the GitLab access token to use for this operation")
args = arg_parser.parse_args()
if args.authn_token_file is not None:
with open(args.authn_token_file, "r") as f:
args.authn_token = f.readline().rstrip()
# Set up the GitLab instance.
lhq = gitlab.Gitlab(url='https://code.librehq.com',
gl = gitlab.Gitlab(url=args.gitlab,
private_token=args.authn_token)
lhq.auth()
gl.auth()
# WARNING: Turning on debugging can cause credentials and other
# sensitive data to be printed on the console.
#
# lhq.enable_debug()
# gl.enable_debug()
projects = lhq.projects.list(iterator=True)
projects = gl.projects.list(iterator=True)
for project in projects:
print(f"*** {project.name_with_namespace} ({project.id}):")
issues = project.issues.list(get_all=True)
......@@ -103,13 +118,13 @@ def main():
# print(f"{issue}")
print("")
groups = lhq.groups.list(iterator=True)
groups = gl.groups.list(iterator=True)
for group in groups:
print(f"{group}")
# This isn't quite right yet:
#
# boards = lhq.boards.list(iterator=True)
# boards = gl.boards.list(iterator=True)
# for board in boards:
# print(f"*** {board} ({board.id}):")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment