Skip to content

Commit 9479932

Browse files
add compact mode to collections list
1 parent 750b236 commit 9479932

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

planet/cli/features.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from planet.clients.features import FeaturesClient
88

99
from .cmds import coro, translate_exceptions
10-
from .options import pretty
10+
from .options import pretty, compact
1111
from .session import CliSession
1212

1313

@@ -63,7 +63,8 @@ async def collection_create(ctx, title, description, pretty):
6363
@translate_exceptions
6464
@coro
6565
@pretty
66-
async def collections_list(ctx, pretty):
66+
@compact
67+
async def collections_list(ctx, pretty, compact):
6768
"""List Features API collections
6869
6970
Example:
@@ -72,7 +73,17 @@ async def collections_list(ctx, pretty):
7273
"""
7374
async with features_client(ctx) as cl:
7475
results = cl.list_collections()
75-
echo_json([c async for c in results], pretty)
76+
77+
if compact:
78+
compact_fields = ('id', 'title', 'description')
79+
output = [{
80+
k: v
81+
for k, v in row.items() if k in compact_fields
82+
} async for row in results]
83+
else:
84+
output = [c async for c in results]
85+
86+
echo_json(output, pretty)
7687

7788

7889
@features.command() # type: ignore

planet/cli/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@
2424

2525
pretty = click.option('--pretty', is_flag=True,
2626
help='Format JSON output.') # type: ignore
27+
28+
compact = click.option('--compact', is_flag=True, help='Use compact output.')

0 commit comments

Comments
 (0)