| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7d04315 commit e5a4379
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -869,6 +869,7 @@ def http_list( | |||
| 869 | 869 | query_data: Optional[Dict[str, Any]] = None, | |
| 870 | 870 | *, | |
| 871 | 871 | iterator: Optional[bool] = None, | |
| 872 | + message_details: Optional[utils.WarnMessageData] = None, | ||
| 872 | 873 | **kwargs: Any, | |
| 873 | 874 | ) -> Union["GitlabList", List[Dict[str, Any]]]: | |
| 874 | 875 | """Make a GET request to the Gitlab server for list-oriented queries. | |
@@ -952,16 +953,29 @@ def should_emit_warning() -> bool: | |||
| 952 | 953 | # Warn the user that they are only going to retrieve `per_page` | |
| 953 | 954 | # maximum items. This is a common cause of issues filed. | |
| 954 | 955 | total_items = "many" if gl_list.total is None else gl_list.total | |
| 955 | - utils.warn( | ||
| 956 | - message=( | ||
| 956 | + if message_details is not None: | ||
| 957 | + message = message_details.message.format_map( | ||
| 958 | + { | ||
| 959 | + "len_items": len(items), | ||
| 960 | + "per_page": gl_list.per_page, | ||
| 961 | + "total_items": total_items, | ||
| 962 | + } | ||
| 963 | + ) | ||
| 964 | + show_caller = message_details.show_caller | ||
| 965 | + else: | ||
| 966 | + message = ( | ||
| 957 | 967 | f"Calling a `list()` method without specifying `get_all=True` or " | |
| 958 | 968 | f"`iterator=True` will return a maximum of {gl_list.per_page} items. " | |
| 959 | 969 | f"Your query returned {len(items)} of {total_items} items. See " | |
| 960 | 970 | f"{_PAGINATION_URL} for more details. If this was done intentionally, " | |
| 961 | 971 | f"then this warning can be supressed by adding the argument " | |
| 962 | 972 | f"`get_all=False` to the `list()` call." | |
| 963 | - ), | ||
| 973 | + ) | ||
| 974 | + show_caller = True | ||
| 975 | + utils.warn( | ||
| 976 | + message=message, | ||
| 964 | 977 | category=UserWarning, | |
| 978 | + show_caller=show_caller, | ||
| 965 | 979 | ) | |
| 966 | 980 | return items | |
| 967 | 981 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + import dataclasses | ||
| 1 | 2 | import email.message | |
| 2 | 3 | import logging | |
| 3 | 4 | import pathlib | |
@@ -205,3 +206,9 @@ def warn( | |||
| 205 | 206 | stacklevel=stacklevel, | |
| 206 | 207 | source=source, | |
| 207 | 208 | ) | |
| 209 | + | ||
| 210 | + | ||
| 211 | + @dataclasses.dataclass | ||
| 212 | + class WarnMessageData: | ||
| 213 | + message: str | ||
| 214 | + show_caller: bool | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | import argparse | |
| 2 | + import json | ||
| 2 | 3 | import operator | |
| 3 | 4 | import sys | |
| 4 | 5 | from typing import Any, Dict, List, Optional, Type, TYPE_CHECKING, Union | |
@@ -140,8 +141,16 @@ def do_list( | |||
| 140 | 141 | ) -> Union[gitlab.base.RESTObjectList, List[gitlab.base.RESTObject]]: | |
| 141 | 142 | if TYPE_CHECKING: | |
| 142 | 143 | assert isinstance(self.mgr, gitlab.mixins.ListMixin) | |
| 144 | + message_details = gitlab.utils.WarnMessageData( | ||
| 145 | + message=( | ||
| 146 | + "Your query returned {len_items} of {total_items} items. To return all " | ||
| 147 | + "items use `--get-all`. To silence this warning use `--no-get-all`." | ||
| 148 | + ), | ||
| 149 | + show_caller=False, | ||
| 150 | + ) | ||
| 151 | + | ||
| 143 | 152 | try: | |
| 144 | - result = self.mgr.list(**self.args) | ||
| 153 | + result = self.mgr.list(**self.args, message_details=message_details) | ||
| 145 | 154 | except Exception as e: # pragma: no cover, cli.die is unit-tested | |
| 146 | 155 | cli.die("Impossible to list objects", e) | |
| 147 | 156 | return result | |
@@ -238,12 +247,25 @@ def _populate_sub_parser_by_class( | |||
| 238 | 247 | ||
| 239 | 248 | sub_parser_action.add_argument("--page", required=False, type=int) | |
| 240 | 249 | sub_parser_action.add_argument("--per-page", required=False, type=int) | |
| 241 | - sub_parser_action.add_argument( | ||
| 250 | + get_all_group = sub_parser_action.add_mutually_exclusive_group() | ||
| 251 | + get_all_group.add_argument( | ||
| 242 | 252 | "--get-all", | |
| 243 | 253 | required=False, | |
| 244 | - action="store_true", | ||
| 254 | + action="store_const", | ||
| 255 | + const=True, | ||
| 256 | + default=None, | ||
| 257 | + dest="get_all", | ||
| 245 | 258 | help="Return all items from the server, without pagination.", | |
| 246 | 259 | ) | |
| 260 | + get_all_group.add_argument( | ||
| 261 | + "--no-get-all", | ||
| 262 | + required=False, | ||
| 263 | + action="store_const", | ||
| 264 | + const=False, | ||
| 265 | + default=None, | ||
| 266 | + dest="get_all", | ||
| 267 | + help="Don't return all items from the server.", | ||
| 268 | + ) | ||
| 247 | 269 | ||
| 248 | 270 | if action_name == "delete": | |
| 249 | 271 | if cls._id_attr is not None: | |
@@ -416,8 +438,6 @@ def get_dict( | |||
| 416 | 438 | class JSONPrinter: | |
| 417 | 439 | @staticmethod | |
| 418 | 440 | def display(d: Union[str, Dict[str, Any]], **_kwargs: Any) -> None: | |
| 419 | - import json # noqa | ||
| 420 | - | ||
| 421 | 441 | print(json.dumps(d)) | |
| 422 | 442 | ||
| 423 | 443 | @staticmethod | |
@@ -426,8 +446,6 @@ def display_list( | |||
| 426 | 446 | fields: List[str], | |
| 427 | 447 | **_kwargs: Any, | |
| 428 | 448 | ) -> None: | |
| 429 | - import json # noqa | ||
| 430 | - | ||
| 431 | 449 | print(json.dumps([get_dict(obj, fields) for obj in data])) | |
| 432 | 450 | ||
| 433 | 451 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments