From a5f0ff04b96a85dd56e679345d589da18368825b Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Wed, 26 Apr 2023 13:15:07 -0700 Subject: [PATCH 01/11] Added an --ids-only option. --- planet/cli/data.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/planet/cli/data.py b/planet/cli/data.py index d138cb51..d2efd63a 100644 --- a/planet/cli/data.py +++ b/planet/cli/data.py @@ -292,8 +292,9 @@ def filter(ctx, default=SEARCH_SORT_DEFAULT, show_default=True, help='Field and direction to order results by.') +@click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @pretty -async def search(ctx, item_types, filter, limit, name, sort, pretty): +async def search(ctx, item_types, filter, limit, name, sort, pretty, ids_only): """Execute a structured item search. This function outputs a series of GeoJSON descriptions, one for each of the @@ -315,7 +316,10 @@ async def search(ctx, item_types, filter, limit, name, sort, pretty): name=name, sort=sort, limit=limit): - echo_json(item, pretty) + if ids_only: + echo_json(item['id'], pretty) + else: + echo_json(item, pretty) @data.command(epilog=valid_item_string) From b58af21d2fe9c966d177b6020c291cc615941cb4 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Wed, 26 Apr 2023 13:31:30 -0700 Subject: [PATCH 02/11] Reordered inputs. --- planet/cli/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planet/cli/data.py b/planet/cli/data.py index d2efd63a..ecec8aff 100644 --- a/planet/cli/data.py +++ b/planet/cli/data.py @@ -294,7 +294,7 @@ def filter(ctx, help='Field and direction to order results by.') @click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @pretty -async def search(ctx, item_types, filter, limit, name, sort, pretty, ids_only): +async def search(ctx, item_types, filter, limit, name, sort, ids_only, pretty): """Execute a structured item search. This function outputs a series of GeoJSON descriptions, one for each of the From 0299b4da29b4f2a9786ca26b11c0b165214e34c5 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Wed, 26 Apr 2023 15:32:32 -0700 Subject: [PATCH 03/11] Ensured that IDs are returned as a CSS for --ids-only --- planet/cli/data.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/planet/cli/data.py b/planet/cli/data.py index ecec8aff..e43556d2 100644 --- a/planet/cli/data.py +++ b/planet/cli/data.py @@ -310,16 +310,18 @@ async def search(ctx, item_types, filter, limit, name, sort, ids_only, pretty): parameter will be applied to the stored quick search. """ async with data_client(ctx) as cl: - + item_ids = [] async for item in cl.search(item_types, search_filter=filter, name=name, sort=sort, limit=limit): if ids_only: - echo_json(item['id'], pretty) + item_ids.append(item['id']) else: echo_json(item, pretty) + if ids_only: + click.echo(', '.join(item_ids)) @data.command(epilog=valid_item_string) From d9db3eff3ea0aabc4d79b983095972b899ea66c6 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Wed, 26 Apr 2023 15:45:21 -0700 Subject: [PATCH 04/11] Removed spaces between item ids --- planet/cli/data.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/planet/cli/data.py b/planet/cli/data.py index e43556d2..c23b186c 100644 --- a/planet/cli/data.py +++ b/planet/cli/data.py @@ -321,7 +321,7 @@ async def search(ctx, item_types, filter, limit, name, sort, ids_only, pretty): else: echo_json(item, pretty) if ids_only: - click.echo(', '.join(item_ids)) + click.echo(','.join(item_ids)) @data.command(epilog=valid_item_string) @@ -375,19 +375,26 @@ async def search_create(ctx, item_types, filter, name, daily_email, pretty): default=LIST_SEARCH_TYPE_DEFAULT, show_default=True, help='Search type filter.') +@click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @limit @pretty -async def search_list(ctx, sort, search_type, limit, pretty): +async def search_list(ctx, sort, search_type, limit, ids_only, pretty): """List saved searches. This function outputs a full JSON description of the saved searches, optionally pretty-printed. """ async with data_client(ctx) as cl: + item_ids = [] async for item in cl.list_searches(sort=sort, search_type=search_type, limit=limit): - echo_json(item, pretty) + if ids_only: + item_ids.append(item['id']) + else: + echo_json(item, pretty) + if ids_only: + click.echo(','.join(item_ids)) @data.command() From 1297f65ffae049c7332bfdee12c553921a4e2fce Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Thu, 27 Apr 2023 10:03:55 -0700 Subject: [PATCH 05/11] Added an --ids-only option for orders get and create. --- planet/cli/orders.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/planet/cli/orders.py b/planet/cli/orders.py index 0341f1d2..5955be83 100644 --- a/planet/cli/orders.py +++ b/planet/cli/orders.py @@ -77,16 +77,20 @@ async def list(ctx, state, limit, pretty): @translate_exceptions @coro @click.argument('order_id', type=click.UUID) +@click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @pretty -async def get(ctx, order_id, pretty): +async def get(ctx, order_id, ids_only, pretty): """Get order This command outputs the order description, optionally pretty-printed. """ async with orders_client(ctx) as cl: order = await cl.get_order(str(order_id)) - - echo_json(order, pretty) + if ids_only: + item_ids = order['products'][0]['item_ids'] + click.echo(','.join(item_ids)) + else: + echo_json(order, pretty) @orders.command() @@ -205,8 +209,9 @@ async def download(ctx, order_id, overwrite, directory, checksum): @translate_exceptions @coro @click.argument("request", type=types.JSON()) +@click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @pretty -async def create(ctx, request: str, pretty): +async def create(ctx, request: str, ids_only, pretty): '''Create an order. This command outputs the created order description, optionally @@ -217,8 +222,11 @@ async def create(ctx, request: str, pretty): ''' async with orders_client(ctx) as cl: order = await cl.create_order(request) - - echo_json(order, pretty) + if ids_only: + item_ids = order['products'][0]['item_ids'] + click.echo(','.join(item_ids)) + else: + echo_json(order, pretty) @orders.command() From e56169c08434c90f3e2b70889671f7b6cc110220 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Thu, 27 Apr 2023 11:08:32 -0700 Subject: [PATCH 06/11] Added an --ids-only option for subscriptions list --- planet/cli/subscriptions.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/planet/cli/subscriptions.py b/planet/cli/subscriptions.py index a10b9c67..088238d7 100644 --- a/planet/cli/subscriptions.py +++ b/planet/cli/subscriptions.py @@ -77,14 +77,23 @@ def subscriptions(ctx, base_url): default=None, help="Select subscriptions in one or more states. Default is all.") @limit +@click.option('--ids-only', + is_flag=True, + help='Returns only the subscription ID.') @click.pass_context @translate_exceptions @coro -async def list_subscriptions_cmd(ctx, status, limit, pretty): +async def list_subscriptions_cmd(ctx, status, limit, ids_only, pretty): """Prints a sequence of JSON-encoded Subscription descriptions.""" async with subscriptions_client(ctx) as client: + subscription_ids = [] async for sub in client.list_subscriptions(status=status, limit=limit): - echo_json(sub, pretty) + if ids_only: + subscription_ids.append(sub['id']) + else: + echo_json(sub, pretty) + if ids_only: + click.echo(','.join(subscription_ids)) @subscriptions.command(name='create') From 40177f156d939d5c1770db7d12cbe10a941ad548 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Thu, 27 Apr 2023 11:13:25 -0700 Subject: [PATCH 07/11] Removed --ids-only from sub list --- planet/cli/subscriptions.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/planet/cli/subscriptions.py b/planet/cli/subscriptions.py index 088238d7..a10b9c67 100644 --- a/planet/cli/subscriptions.py +++ b/planet/cli/subscriptions.py @@ -77,23 +77,14 @@ def subscriptions(ctx, base_url): default=None, help="Select subscriptions in one or more states. Default is all.") @limit -@click.option('--ids-only', - is_flag=True, - help='Returns only the subscription ID.') @click.pass_context @translate_exceptions @coro -async def list_subscriptions_cmd(ctx, status, limit, ids_only, pretty): +async def list_subscriptions_cmd(ctx, status, limit, pretty): """Prints a sequence of JSON-encoded Subscription descriptions.""" async with subscriptions_client(ctx) as client: - subscription_ids = [] async for sub in client.list_subscriptions(status=status, limit=limit): - if ids_only: - subscription_ids.append(sub['id']) - else: - echo_json(sub, pretty) - if ids_only: - click.echo(','.join(subscription_ids)) + echo_json(sub, pretty) @subscriptions.command(name='create') From b3b35d59edc71f20ffdcb88b24006e5e5dcd08a0 Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Thu, 27 Apr 2023 11:14:16 -0700 Subject: [PATCH 08/11] Removed --ids-only from orders create --- planet/cli/orders.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/planet/cli/orders.py b/planet/cli/orders.py index 5955be83..fb1cf6d6 100644 --- a/planet/cli/orders.py +++ b/planet/cli/orders.py @@ -209,9 +209,8 @@ async def download(ctx, order_id, overwrite, directory, checksum): @translate_exceptions @coro @click.argument("request", type=types.JSON()) -@click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @pretty -async def create(ctx, request: str, ids_only, pretty): +async def create(ctx, request: str, pretty): '''Create an order. This command outputs the created order description, optionally @@ -222,10 +221,6 @@ async def create(ctx, request: str, ids_only, pretty): ''' async with orders_client(ctx) as cl: order = await cl.create_order(request) - if ids_only: - item_ids = order['products'][0]['item_ids'] - click.echo(','.join(item_ids)) - else: echo_json(order, pretty) From dd2e27fa6b45ed84949abdb2d82dbea4f57f418b Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Thu, 27 Apr 2023 11:14:48 -0700 Subject: [PATCH 09/11] Added back --ids-only to orders create. --- planet/cli/orders.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/planet/cli/orders.py b/planet/cli/orders.py index fb1cf6d6..5955be83 100644 --- a/planet/cli/orders.py +++ b/planet/cli/orders.py @@ -209,8 +209,9 @@ async def download(ctx, order_id, overwrite, directory, checksum): @translate_exceptions @coro @click.argument("request", type=types.JSON()) +@click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @pretty -async def create(ctx, request: str, pretty): +async def create(ctx, request: str, ids_only, pretty): '''Create an order. This command outputs the created order description, optionally @@ -221,6 +222,10 @@ async def create(ctx, request: str, pretty): ''' async with orders_client(ctx) as cl: order = await cl.create_order(request) + if ids_only: + item_ids = order['products'][0]['item_ids'] + click.echo(','.join(item_ids)) + else: echo_json(order, pretty) From b1a91089e6ccf440f56aa1adcc8c0178d4192aea Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Thu, 27 Apr 2023 11:18:03 -0700 Subject: [PATCH 10/11] Removed --ids-only from orders create --- planet/cli/orders.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/planet/cli/orders.py b/planet/cli/orders.py index 5955be83..fb1cf6d6 100644 --- a/planet/cli/orders.py +++ b/planet/cli/orders.py @@ -209,9 +209,8 @@ async def download(ctx, order_id, overwrite, directory, checksum): @translate_exceptions @coro @click.argument("request", type=types.JSON()) -@click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @pretty -async def create(ctx, request: str, ids_only, pretty): +async def create(ctx, request: str, pretty): '''Create an order. This command outputs the created order description, optionally @@ -222,10 +221,6 @@ async def create(ctx, request: str, ids_only, pretty): ''' async with orders_client(ctx) as cl: order = await cl.create_order(request) - if ids_only: - item_ids = order['products'][0]['item_ids'] - click.echo(','.join(item_ids)) - else: echo_json(order, pretty) From 601f992c6f6d7159c3f660f90b96fb27a5bea2ed Mon Sep 17 00:00:00 2001 From: Kevin Lacaille Date: Thu, 27 Apr 2023 11:26:47 -0700 Subject: [PATCH 11/11] Removed --ids-only from data seach list and added to search run. --- planet/cli/data.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/planet/cli/data.py b/planet/cli/data.py index c23b186c..f1b95165 100644 --- a/planet/cli/data.py +++ b/planet/cli/data.py @@ -375,26 +375,19 @@ async def search_create(ctx, item_types, filter, name, daily_email, pretty): default=LIST_SEARCH_TYPE_DEFAULT, show_default=True, help='Search type filter.') -@click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @limit @pretty -async def search_list(ctx, sort, search_type, limit, ids_only, pretty): +async def search_list(ctx, sort, search_type, limit, pretty): """List saved searches. This function outputs a full JSON description of the saved searches, optionally pretty-printed. """ async with data_client(ctx) as cl: - item_ids = [] async for item in cl.list_searches(sort=sort, search_type=search_type, limit=limit): - if ids_only: - item_ids.append(item['id']) - else: - echo_json(item, pretty) - if ids_only: - click.echo(','.join(item_ids)) + echo_json(item, pretty) @data.command() @@ -408,16 +401,23 @@ async def search_list(ctx, sort, search_type, limit, ids_only, pretty): show_default=True, help='Field and direction to order results by.') @limit +@click.option('--ids-only', is_flag=True, help='Returns only the item IDs.') @pretty -async def search_run(ctx, search_id, sort, limit, pretty): +async def search_run(ctx, search_id, sort, limit, ids_only, pretty): """Execute a saved structured item search. This function outputs a series of GeoJSON descriptions, one for each of the returned items, optionally pretty-printed. """ async with data_client(ctx) as cl: + item_ids = [] async for item in cl.run_search(search_id, sort=sort, limit=limit): - echo_json(item, pretty) + if ids_only: + item_ids.append(item['id']) + else: + echo_json(item, pretty) + if ids_only: + click.echo(','.join(item_ids)) @data.command(epilog=valid_item_string)