-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added --ids-only option #940
base: main
Are you sure you want to change the base?
Changes from all commits
a5f0ff0
b58af21
0299b4d
d9db3ef
1297f65
e56169c
40177f1
b3b35d5
dd2e27f
b1a9108
601f992
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, ids_only, pretty): | ||
"""Execute a structured item search. | ||
|
||
This function outputs a series of GeoJSON descriptions, one for each of the | ||
|
@@ -309,13 +310,18 @@ async def search(ctx, item_types, filter, limit, name, sort, 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): | ||
echo_json(item, pretty) | ||
if ids_only: | ||
item_ids.append(item['id']) | ||
else: | ||
echo_json(item, pretty) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kevinlacaille In #645 I'm pushing back a little on this feature request, but if we did it, this is completely sound. Append to list or print to terminal, this is easy to read and understand. It's symmetry in action. |
||
if ids_only: | ||
click.echo(','.join(item_ids)) | ||
|
||
|
||
@data.command(epilog=valid_item_string) | ||
|
@@ -395,16 +401,23 @@ async def search_list(ctx, sort, search_type, limit, 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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kevinlacaille #645 is only about getting a list of ids from search. Let's not extend to the orders CLI here. Can you remove the changes to planet/cli/orders.py? |
||
@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() | ||
|
@@ -217,8 +221,7 @@ async def create(ctx, request: str, pretty): | |
''' | ||
async with orders_client(ctx) as cl: | ||
order = await cl.create_order(request) | ||
|
||
echo_json(order, pretty) | ||
echo_json(order, pretty) | ||
|
||
|
||
@orders.command() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #645 we've recognized that search results may cover multiple item_types and that mixing their ids together sets a user up for failure. @kevinlacaille what would you think about this?