| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6b47c26 commit f553fd3
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,11 +200,15 @@ def _populate_sub_parser_by_class( | |||
| 200 | 200 | mgr_cls_name = f"{cls.__name__}Manager" | |
| 201 | 201 | mgr_cls = getattr(gitlab.v4.objects, mgr_cls_name) | |
| 202 | 202 | ||
| 203 | + action_parsers: Dict[str, argparse.ArgumentParser] = {} | ||
| 203 | 204 | for action_name in ["list", "get", "create", "update", "delete"]: | |
| 204 | 205 | if not hasattr(mgr_cls, action_name): | |
| 205 | 206 | continue | |
| 206 | 207 | ||
| 207 | - sub_parser_action = sub_parser.add_parser(action_name) | ||
| 208 | + sub_parser_action = sub_parser.add_parser( | ||
| 209 | + action_name, conflict_handler="resolve" | ||
| 210 | + ) | ||
| 211 | + action_parsers[action_name] = sub_parser_action | ||
| 208 | 212 | sub_parser_action.add_argument("--sudo", required=False) | |
| 209 | 213 | if mgr_cls._from_parent_attrs: | |
| 210 | 214 | for x in mgr_cls._from_parent_attrs: | |
@@ -268,7 +272,11 @@ def _populate_sub_parser_by_class( | |||
| 268 | 272 | if cls.__name__ in cli.custom_actions: | |
| 269 | 273 | name = cls.__name__ | |
| 270 | 274 | for action_name in cli.custom_actions[name]: | |
| 271 | - sub_parser_action = sub_parser.add_parser(action_name) | ||
| 275 | + # NOTE(jlvillal): If we put a function for the `default` value of | ||
| 276 | + # the `get` it will always get called, which will break things. | ||
| 277 | + sub_parser_action = action_parsers.get(action_name) | ||
| 278 | + if sub_parser_action is None: | ||
| 279 | + sub_parser_action = sub_parser.add_parser(action_name) | ||
| 272 | 280 | # Get the attributes for URL/path construction | |
| 273 | 281 | if mgr_cls._from_parent_attrs: | |
| 274 | 282 | for x in mgr_cls._from_parent_attrs: | |
@@ -298,7 +306,11 @@ def _populate_sub_parser_by_class( | |||
| 298 | 306 | if mgr_cls.__name__ in cli.custom_actions: | |
| 299 | 307 | name = mgr_cls.__name__ | |
| 300 | 308 | for action_name in cli.custom_actions[name]: | |
| 301 | - sub_parser_action = sub_parser.add_parser(action_name) | ||
| 309 | + # NOTE(jlvillal): If we put a function for the `default` value of | ||
| 310 | + # the `get` it will always get called, which will break things. | ||
| 311 | + sub_parser_action = action_parsers.get(action_name) | ||
| 312 | + if sub_parser_action is None: | ||
| 313 | + sub_parser_action = sub_parser.add_parser(action_name) | ||
| 302 | 314 | if mgr_cls._from_parent_attrs: | |
| 303 | 315 | for x in mgr_cls._from_parent_attrs: | |
| 304 | 316 | sub_parser_action.add_argument( | |
@@ -326,16 +338,15 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: | |||
| 326 | 338 | subparsers.required = True | |
| 327 | 339 | ||
| 328 | 340 | # populate argparse for all Gitlab Object | |
| 329 | - classes = [] | ||
| 341 | + classes = set() | ||
| 330 | 342 | for cls in gitlab.v4.objects.__dict__.values(): | |
| 331 | 343 | if not isinstance(cls, type): | |
| 332 | 344 | continue | |
| 333 | 345 | if issubclass(cls, gitlab.base.RESTManager): | |
| 334 | 346 | if cls._obj_cls is not None: | |
| 335 | - classes.append(cls._obj_cls) | ||
| 336 | - classes.sort(key=operator.attrgetter("__name__")) | ||
| 347 | + classes.add(cls._obj_cls) | ||
| 337 | 348 | ||
| 338 | - for cls in classes: | ||
| 349 | + for cls in sorted(classes, key=operator.attrgetter("__name__")): | ||
| 339 | 350 | arg_name = cli.cls_to_what(cls) | |
| 340 | 351 | object_group = subparsers.add_parser(arg_name) | |
| 341 | 352 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments