Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: duplicate subparsers being added to argparse#2014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nejch merged 1 commit intomainfromjlvillal/python3.11beta1
May 9, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletionsgitlab/v4/cli.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -200,11 +200,15 @@ def _populate_sub_parser_by_class(
mgr_cls_name = f"{cls.__name__}Manager"
mgr_cls = getattr(gitlab.v4.objects, mgr_cls_name)

action_parsers: Dict[str, argparse.ArgumentParser] = {}
for action_name in ["list", "get", "create", "update", "delete"]:
if not hasattr(mgr_cls, action_name):
continue

sub_parser_action = sub_parser.add_parser(action_name)
sub_parser_action = sub_parser.add_parser(
action_name, conflict_handler="resolve"
)
action_parsers[action_name] = sub_parser_action
sub_parser_action.add_argument("--sudo", required=False)
if mgr_cls._from_parent_attrs:
for x in mgr_cls._from_parent_attrs:
Expand DownExpand Up@@ -268,7 +272,11 @@ def _populate_sub_parser_by_class(
if cls.__name__ in cli.custom_actions:
name = cls.__name__
for action_name in cli.custom_actions[name]:
sub_parser_action = sub_parser.add_parser(action_name)
# NOTE(jlvillal): If we put a function for the `default` value of
# the `get` it will always get called, which will break things.
sub_parser_action = action_parsers.get(action_name)
if sub_parser_action is None:
sub_parser_action = sub_parser.add_parser(action_name)
# Get the attributes for URL/path construction
if mgr_cls._from_parent_attrs:
for x in mgr_cls._from_parent_attrs:
Expand DownExpand Up@@ -298,7 +306,11 @@ def _populate_sub_parser_by_class(
if mgr_cls.__name__ in cli.custom_actions:
name = mgr_cls.__name__
for action_name in cli.custom_actions[name]:
sub_parser_action = sub_parser.add_parser(action_name)
# NOTE(jlvillal): If we put a function for the `default` value of
# the `get` it will always get called, which will break things.
sub_parser_action = action_parsers.get(action_name)
if sub_parser_action is None:
sub_parser_action = sub_parser.add_parser(action_name)
if mgr_cls._from_parent_attrs:
for x in mgr_cls._from_parent_attrs:
sub_parser_action.add_argument(
Expand DownExpand Up@@ -326,16 +338,15 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
subparsers.required = True

# populate argparse for all Gitlab Object
classes =[]
classes =set()
for cls in gitlab.v4.objects.__dict__.values():
if not isinstance(cls, type):
continue
if issubclass(cls, gitlab.base.RESTManager):
if cls._obj_cls is not None:
classes.append(cls._obj_cls)
classes.sort(key=operator.attrgetter("__name__"))
classes.add(cls._obj_cls)

for cls in classes:
for cls insorted(classes, key=operator.attrgetter("__name__")):
arg_name = cli.cls_to_what(cls)
object_group = subparsers.add_parser(arg_name)

Expand Down
Empty file addedtests/unit/v4/__init__.py
View file
Open in desktop
Empty file.

[8]ページ先頭

©2009-2025 Movatter.jp