Skip to content

Commit d63c1d0

Browse files
committed
address feedback and typos
- make it clearer that name or ID can be used to lookup items - add typed dicts to represent API responses/resources - accept typed dict or name/ID when possible - raise MissingResource when attempting a get by name with no match - use positional/keyword-only parameters in client methods
1 parent 0324726 commit d63c1d0

File tree

4 files changed

+124
-89
lines changed

4 files changed

+124
-89
lines changed

examples/mosaics-cli.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/bin/bash
22

3-
echo -e "Global Basemap Series"
3+
echo -e "List the mosaic series that have the word Global in their name"
44
planet mosaics series list --name-contains=Global | jq .[].name
55

6-
echo -e "\nLatest Global Monthly"
6+
echo -e "\nWhat is the latest mosaic in the series named Global Monthly, with output indented"
77
planet mosaics series list-mosaics "Global Monthly" --latest --pretty
88

9-
echo -e "\nHow Many Quads?"
10-
planet mosaics search 09462e5a-2af0-4de3-a710-e9010d8d4e58 --bbox=-100,40,-100,40.1
9+
echo -e "\nHow many quads are in the mosaic with this ID (name also accepted!)?"
10+
planet mosaics search 09462e5a-2af0-4de3-a710-e9010d8d4e58 --bbox=-100,40,-100,40.1 | jq .[].id
1111

12-
echo -e "\nWhat Scenes Contributed to Quad?"
12+
echo -e "\nWhat scenes contributed to this quad in the mosaic with this ID (name also accepted)?"
1313
planet mosaics contributions 09462e5a-2af0-4de3-a710-e9010d8d4e58 455-1273
1414

15-
echo -e "\nDownload Them!"
15+
echo -e "\nDownload them to a directory named quads!"
1616
planet mosaics download 09462e5a-2af0-4de3-a710-e9010d8d4e58 --bbox=-100,40,-100,40.1 --output-dir=quads

planet/cli/mosaics.py

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,32 @@ def series():
8787

8888

8989
@command(mosaics, name="contributions")
90-
@click.argument("name")
90+
@click.argument("name_or_id")
9191
@click.argument("quad")
92-
async def quad_contributions(ctx, name, quad, pretty):
93-
'''Get contributing scenes for a mosaic quad
92+
async def quad_contributions(ctx, name_or_id, quad, pretty):
93+
'''Get contributing scenes for a quad in a mosaic specified by name or ID
9494
9595
Example:
9696
9797
planet mosaics contribution global_monthly_2025_04_mosaic 575-1300
9898
'''
9999
async with client(ctx) as cl:
100-
item = await cl.get_quad(name, quad)
100+
item = await cl.get_quad(name_or_id, quad)
101101
await _output(cl.get_quad_contributions(item), pretty)
102102

103103

104104
@command(mosaics, name="info")
105-
@click.argument("name", required=True)
105+
@click.argument("name_or_id", required=True)
106106
@include_links
107-
async def mosaic_info(ctx, name, pretty, links):
108-
"""Get information for a specific mosaic
107+
async def mosaic_info(ctx, name_or_id, pretty, links):
108+
"""Get information for a mosaic specified by name or ID
109109
110110
Example:
111111
112112
planet mosaics info global_monthly_2025_04_mosaic
113113
"""
114114
async with client(ctx) as cl:
115-
await _output(cl.get_mosaic(name), pretty, links)
115+
await _output(cl.get_mosaic(name_or_id), pretty, links)
116116

117117

118118
@command(mosaics, name="list")
@@ -128,11 +128,11 @@ async def mosaics_list(ctx,
128128
acquired_lt,
129129
pretty,
130130
links):
131-
"""List all mosaics
131+
"""List information for all available mosaics
132132
133133
Example:
134134
135-
planet mosaics info global_monthly_2025_04_mosaic
135+
planet mosaics list --name-contains global_monthly
136136
"""
137137
async with client(ctx) as cl:
138138
await _output(
@@ -145,17 +145,17 @@ async def mosaics_list(ctx,
145145

146146

147147
@command(series, name="info")
148-
@click.argument("name", required=True)
148+
@click.argument("name_or_id", required=True)
149149
@include_links
150-
async def series_info(ctx, name, pretty, links):
151-
"""Get information for a specific series
150+
async def series_info(ctx, name_or_id, pretty, links):
151+
"""Get information for a series specified by name or ID
152152
153153
Example:
154154
155155
planet series info "Global Quarterly"
156156
"""
157157
async with client(ctx) as cl:
158-
await _output(cl.get_series(name), pretty, links)
158+
await _output(cl.get_series(name_or_id), pretty, links)
159159

160160

161161
@command(series, name="list")
@@ -171,7 +171,7 @@ async def series_list(ctx,
171171
acquired_lt,
172172
pretty,
173173
links):
174-
"""List series
174+
"""List information for available series
175175
176176
Example:
177177
@@ -180,39 +180,39 @@ async def series_list(ctx,
180180
async with client(ctx) as cl:
181181
await _output(
182182
cl.list_series(
183-
name_contains,
184-
interval,
185-
acquired_gt,
186-
acquired_lt,
183+
name_contains=name_contains,
184+
interval=interval,
185+
acquired_gt=acquired_gt,
186+
acquired_lt=acquired_lt,
187187
),
188188
pretty,
189189
links)
190190

191191

192192
@command(series, name="list-mosaics")
193-
@click.argument("name", required=True)
193+
@click.argument("name_or_id", required=True)
194194
@click.option("--latest",
195195
is_flag=True,
196196
help=("Get the latest mosaic in the series"))
197197
@acquired_gt
198198
@acquired_lt
199199
@include_links
200200
async def list_series_mosaics(ctx,
201-
name,
201+
name_or_id,
202202
acquired_gt,
203203
acquired_lt,
204204
latest,
205-
links,
206-
pretty):
207-
"""List mosaics in a series
205+
pretty,
206+
links):
207+
"""List mosaics in a series specified by name or ID
208208
209209
Example:
210210
211211
planet mosaics series list-mosaics global_monthly_2025_04_mosaic
212212
"""
213213
async with client(ctx) as cl:
214214
await _output(
215-
cl.list_series_mosaics(name,
215+
cl.list_series_mosaics(name_or_id,
216216
acquired_gt=acquired_gt,
217217
acquired_lt=acquired_lt,
218218
latest=latest),
@@ -221,24 +221,24 @@ async def list_series_mosaics(ctx,
221221

222222

223223
@command(mosaics, name="search")
224-
@click.argument("name", required=True)
224+
@click.argument("name_or_id", required=True)
225225
@bbox
226226
@geometry
227227
@click.option("--summary",
228228
is_flag=True,
229229
help=("Get a count of how many quads would be returned"))
230230
@include_links
231-
async def list_quads(ctx, name, bbox, geometry, summary, links, pretty):
232-
"""Search quads
231+
async def list_quads(ctx, name_or_id, bbox, geometry, summary, pretty, links):
232+
"""Search quads in a mosaic specified by name or ID
233233
234234
Example:
235235
236236
planet mosaics search global_monthly_2025_04_mosaic --bbox -100,40,-100,41
237237
"""
238238
async with client(ctx) as cl:
239-
mosaic = await cl.get_mosaic(name)
239+
mosaic = await cl.get_mosaic(name_or_id)
240240
if mosaic is None:
241-
raise click.ClickException("No mosaic named " + name)
241+
raise click.ClickException("No mosaic named " + name_or_id)
242242
await _output(
243243
cl.list_quads(mosaic,
244244
minimal=False,
@@ -250,28 +250,27 @@ async def list_quads(ctx, name, bbox, geometry, summary, links, pretty):
250250

251251

252252
@command(mosaics, name="download")
253-
@click.argument("name", required=True)
253+
@click.argument("name_or_id", required=True)
254254
@click.option('--output-dir',
255-
default='.',
256-
help=('Directory for file download.'),
255+
help=('Directory for file download. Defaults to mosaic name'),
257256
type=click.Path(exists=True,
258257
resolve_path=True,
259258
writable=True,
260259
file_okay=False))
261260
@bbox
262261
@geometry
263-
async def download(ctx, name, output_dir, bbox, geometry, **kwargs):
264-
"""Download quads from a mosaic
262+
async def download(ctx, name_or_id, output_dir, bbox, geometry, **kwargs):
263+
"""Download quads from a mosaic by name or ID
265264
266265
Example:
267266
268267
planet mosaics search global_monthly_2025_04_mosaic --bbox -100,40,-100,41
269268
"""
270269
quiet = ctx.obj['QUIET']
271270
async with client(ctx) as cl:
272-
mosaic = await cl.get_mosaic(name)
271+
mosaic = await cl.get_mosaic(name_or_id)
273272
if mosaic is None:
274-
raise click.ClickException("No mosaic named " + name)
273+
raise click.ClickException("No mosaic named " + name_or_id)
275274
await cl.download_quads(mosaic,
276275
bbox=bbox,
277276
geometry=geometry,

0 commit comments

Comments
 (0)