Skip to content

Commit

Permalink
Make source_type/state single args to avoid breaking client changes
Browse files Browse the repository at this point in the history
  • Loading branch information
whipps committed Dec 6, 2024
1 parent 5d8d513 commit 71562d3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docs/cli/cli-orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ length of the array.
#### Filtering

The `list` command supports filtering on a variety of fields:
* `--state`: Filter by one or more states. Options include `queued`, `failed`, `success`, `partial` and `cancelled`.
* `--source-type`: Filter by one or more source types. Options include `scenes`, `basemaps`, or `all`. The default is `all`.
* `--state`: Filter by order state. Options include `queued`, `failed`, `success`, `partial` and `cancelled`.
* `--source-type`: Filter by source type. Options include `scenes`, `basemaps`, or `all`. The default is `all`.
* `--name`: Filter by name.
* `--name-contains`: Only return orders with a name that contains the provided string.
* `--created-on`: Filter on the order creation time or an interval of creation times.
Expand Down
10 changes: 4 additions & 6 deletions planet/cli/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ def orders(ctx, base_url):
@translate_exceptions
@coro
@click.option('--state',
help='Filter by one or more states.',
multiple=True,
help='Filter by state.',
type=click.Choice(planet.clients.orders.ORDER_STATE_SEQUENCE,
case_sensitive=False))
@click.option(
'--source-type',
default=["all"],
multiple=True,
help="""Filter by one or more source types. See documentation for all
available types. Default is all.""")
default="all",
help="""Filter by source type. See documentation for all available types.
Default is all.""")
@click.option('--name', help="filter by name")
@click.option(
'--name-contains',
Expand Down
5 changes: 2 additions & 3 deletions planet/cli/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ def subscriptions(ctx, base_url):
@click.option('--name', help="filter by name")
@click.option(
'--source-type',
multiple=True,
help="""Filter subscriptions by one or more source types. See documentation
for all available types. Default is all.""")
help="""Filter subscriptions by source type. See documentation for all
available types. Default is all.""")
@click.option(
'--start-time',
help="""Filter subscriptions by start time or interval. See documentation
Expand Down
21 changes: 10 additions & 11 deletions planet/clients/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ async def wait(self,
return current_state

async def list_orders(self,
state: Optional[Sequence[str]] = None,
source_type: Optional[Sequence[str]] = None,
state: Optional[str] = None,
source_type: Optional[str] = None,
name: Optional[str] = None,
name__contains: Optional[str] = None,
created_on: Optional[str] = None,
Expand All @@ -483,8 +483,8 @@ async def list_orders(self,
single result description or return a list of descriptions.
Parameters:
state (Set[str]): include orders with a state in this set.
source_type (Set[str]): include orders with a source type in this set.
state (str): filter by state.
source_type (str): filter by source type.
name (str): filter by name.
name__contains (str): only include orders with names containing this string.
created_on (str): filter by creation date-time or interval.
Expand Down Expand Up @@ -525,7 +525,7 @@ async def list_orders(self,
url = self._orders_url()
params: Dict[str, Union[str, Sequence[str], bool]] = {}
if source_type is not None:
params["source_type"] = [val for val in source_type]
params["source_type"] = source_type
else:
params["source_type"] = "all"
if name is not None:
Expand All @@ -541,12 +541,11 @@ async def list_orders(self,
if sort_by is not None:
params["sort_by"] = sort_by
if state:
for s in state:
if s not in ORDER_STATE_SEQUENCE:
raise exceptions.ClientError(
f'Order state ({s}) is not a valid state. '
f'Valid states are {ORDER_STATE_SEQUENCE}')
params['state'] = [val for val in state]
if state not in ORDER_STATE_SEQUENCE:
raise exceptions.ClientError(
f'Order state ({state}) is not a valid state. '
f'Valid states are {ORDER_STATE_SEQUENCE}')
params['state'] = state

response = await self._session.request(method='GET',
url=url,
Expand Down
7 changes: 3 additions & 4 deletions planet/clients/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def list_subscriptions(self,
hosting: Optional[bool] = None,
name__contains: Optional[str] = None,
name: Optional[str] = None,
source_type: Optional[Sequence[str]] = None,
source_type: Optional[str] = None,
start_time: Optional[str] = None,
status: Optional[Sequence[str]] = None,
sort_by: Optional[str] = None,
Expand All @@ -86,8 +86,7 @@ async def list_subscriptions(self,
name__contains (str): only return subscriptions with a
name that contains the given string.
name (str): filter by name.
source_type (Set[str]): include subscriptions with a source type in
this set.
source_type (str): filter by source type.
start_time (str): filter by start time or interval.
status (Set[str]): include subscriptions with a status in this set.
sort_by (str): fields to sort subscriptions by. Multiple
Expand Down Expand Up @@ -141,7 +140,7 @@ class _SubscriptionsPager(Paged):
if name is not None:
params['name'] = name
if source_type is not None:
params['source_type'] = [val for val in source_type]
params['source_type'] = source_type
if start_time is not None:
params['start_time'] = start_time
if status is not None:
Expand Down

0 comments on commit 71562d3

Please sign in to comment.