Skip to content
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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Added --ids-only option #940

wants to merge 11 commits into from

Conversation

kevinlacaille
Copy link
Contributor

@kevinlacaille kevinlacaille commented Apr 26, 2023

Related Issue(s):

Closes #645

Proposed Changes:

For inclusion in changelog (if applicable):

  1. Added a flag, ids-only, which returns only the item IDs from a search or order, to the following functions: data search, data search-run, orders get

Not intended for changelog:

Diff of User Interface

Old behavior:

planet <command>  | jq -r .id | tr '\n' ',' | sed 's/.$//'
Comma separate list of item ids

For example, data search

planet data search psscene --limit 10 | jq -r .id | tr '\n' ',' | sed 's/.$//'                      
20230427_104445_51_248b,20230427_072107_90_242e,20230427_071646_44_248c,20230303_161806_29_24bb,20230303_161803_87_24bb,20230427_104441_19_248b,20230427_104126_76_248b,20230427_103940_90_248b,20230427_100416_94_249a,20230427_082511_30_24bc%                                                                                    

New behavior:

planet <command>  --ids-only
Comma separate list of item ids

data search

planet data search psscene --limit 10 --ids-only                                                      
20230426_065727_44_2479,20230426_171106_48_2423,20230426_174958_25_24b9,20230426_170845_64_2423,20230426_170834_96_2423,20230426_165943_74_2416,20230426_161130_11_24b5,20230426_161044_90_24b5,20230426_092428_35_2432,20230426_085011_34_2465

data search-run

planet data search-run 42b0e1ff085d4a57a34236d36674703e --limit 10 --ids-only   
20230427_072359_07_2458,20230427_072754_74_242b,20230427_061032_97_2473,20230427_071806_81_242b,20230427_052015_19_2446,20230426_140020_91_2276,20230426_135909_86_2276,20230427_025450_23_2415,20230427_072850_11_242b,20230427_070835_13_24af

orders get

planet orders get 38d89352-e90a-4cd7-9964-dfe629d5081b --ids-only
20230409_100344_03_2484,20230409_100341_88_2484,20230409_101856_12_2414,20230409_101854_08_2414,20230406_100337_05_2488

PR Checklist:

  • This PR is as small and focused as possible
  • If this PR includes proposed changes for inclusion in the changelog, the title of this PR summarizes those changes and is ready for inclusion in the Changelog.
  • [] I have updated docstrings for function changes and docs in the 'docs' folder for user interface / behavior changes
  • [] This PR does not break any examples or I have updated them

(Optional) @mentions for Notifications:

@kevinlacaille kevinlacaille added enhancement CLI/SDK Interface Update the CLI and SDK to the finalized interface labels Apr 26, 2023
@kevinlacaille kevinlacaille self-assigned this Apr 26, 2023
@kevinlacaille kevinlacaille changed the title Added an --ids-only option. Added --ids-only option Apr 26, 2023
@cholmes
Copy link
Member

cholmes commented Apr 26, 2023

I realized I never explained this in the original ticket, but the key for this is that the output can be directly piped into the orders request command. So it needs to remove the " and replace the newlines with commas. So output should be like 20230120_003217_79_24ab,20230120_003215_49_24ab,20230120_003213_19_24ab,20230120_003210_89_24ab,20230128_003142_04_24ab

@kevinlacaille kevinlacaille marked this pull request as ready for review April 27, 2023 18:31
if ids_only:
item_ids.append(item['id'])
else:
echo_json(item, pretty)
Copy link
Contributor

@sgillies sgillies Apr 27, 2023

Choose a reason for hiding this comment

The 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.

@@ -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.')
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

@@ -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 = []
Copy link
Contributor

@sgillies sgillies May 4, 2023

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?

Suggested change
item_ids = []
if ids_only and len(item_types) > 1:
raise ClickException("item id output is not allowed when multiple item types have been searched.")
item_ids = []

Copy link
Contributor

@sgillies sgillies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinlacaille I'm in favor, but would like to see 2 changes.

@jreiberkyle
Copy link
Contributor

I am against merging this at this time. Lets have more discussion.

@kevinlacaille kevinlacaille linked an issue May 4, 2023 that may be closed by this pull request
@jreiberkyle jreiberkyle changed the base branch from 2.0.1 to main May 11, 2023 03:44
@asonnenschein asonnenschein added the 2024-revisit SDK committee reviewed and marked for follow-up label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2024-revisit SDK committee reviewed and marked for follow-up CLI/SDK Interface Update the CLI and SDK to the finalized interface enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an --ids-only flag to easily extract ID's from a search.
5 participants