| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
import argparse |
| 14 |
|
| 15 |
from osc_lib.cli import parseractions |
| 16 |
from osc_lib.i18n import _ |
| 17 |
|
| 18 |
|
| 19 |
def add_marker_pagination_option_to_parser( |
| 20 |
parser: argparse.ArgumentParser, |
| 21 |
) -> None: |
| 22 |
"""Add marker-based pagination options to the parser. |
| 23 |
|
| 24 |
APIs that use marker-based paging use the marker and limit query parameters |
| 25 |
to paginate through items in a collection. |
| 26 |
|
| 27 |
Marker-based pagination is often used in cases where the length of the |
| 28 |
total set of items is either changing frequently, or where the total length |
| 29 |
might not be known upfront. |
| 30 |
""" |
| 31 |
parser.add_argument( |
| 32 |
'--limit', |
| 33 |
metavar='<limit>', |
| 34 |
type=int, |
| 35 |
action=parseractions.NonNegativeAction, |
| 36 |
help=_( |
| 37 |
'The maximum number of entries to return. If the value exceeds ' |
| 38 |
'the server-defined maximum, then the maximum value will be used.' |
| 39 |
), |
| 40 |
) |
| 41 |
parser.add_argument( |
| 42 |
'--marker', |
| 43 |
metavar='<marker>', |
| 44 |
default=None, |
| 45 |
help=_( |
| 46 |
'The first position in the collection to return results from. ' |
| 47 |
'This should be a value that was returned in a previous request.' |
| 48 |
), |
| 49 |
) |
| 50 |
|
| 51 |
|
| 52 |
def add_offset_pagination_option_to_parser( |
| 53 |
parser: argparse.ArgumentParser, |
| 54 |
) -> None: |
| 55 |
"""Add offset-based pagination options to the parser. |
| 56 |
|
| 57 |
APIs that use offset-based paging use the offset and limit query parameters |
| 58 |
to paginate through items in a collection. |
| 59 |
|
| 60 |
Offset-based pagination is often used where the list of items is of a fixed |
| 61 |
and predetermined length. |
| 62 |
""" |
| 63 |
parser.add_argument( |
| 64 |
'--limit', |
| 65 |
metavar='<limit>', |
| 66 |
type=int, |
| 67 |
action=parseractions.NonNegativeAction, |
| 68 |
help=_( |
| 69 |
'The maximum number of entries to return. If the value exceeds ' |
| 70 |
'the server-defined maximum, then the maximum value will be used.' |
| 71 |
), |
| 72 |
) |
| 73 |
parser.add_argument( |
| 74 |
'--offset', |
| 75 |
metavar='<offset>', |
| 76 |
type=int, |
| 77 |
action=parseractions.NonNegativeAction, |
| 78 |
default=None, |
| 79 |
help=_( |
| 80 |
'The (zero-based) offset of the first item in the collection to ' |
| 81 |
'return.' |
| 82 |
), |
| 83 |
) |