Skip to content

Commit

Permalink
Add -o flag to metadata download
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Mar 16, 2022
1 parent d81e3b3 commit 36af9de
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions isic_cli/cli/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,21 @@ def validate(csv_path: Path):
type=IntRange(min=0),
help='Use a value of 0 to disable the limit.',
)
@click.option(
'-o',
'--outfile',
type=click.Path(file_okay=True, dir_okay=False, path_type=Path),
help='A filepath to write the output CSV to.',
)
@click.pass_obj
@suggest_guest_login
def download(ctx: IsicContext, search: Union[None, str], collections: Union[None, str], limit: int):
def download(
ctx: IsicContext,
search: Union[None, str],
collections: Union[None, str],
limit: int,
outfile: Path,
):
"""
Download metadata from the ISIC Archive.
Expand All @@ -139,7 +151,12 @@ def download(ctx: IsicContext, search: Union[None, str], collections: Union[None
headers, records = _extract_metadata(images, progress, task)

if records:
writer = csv.DictWriter(sys.stdout, headers)
if outfile:
stream = click.open_file(outfile, 'w')
else:
stream = click.get_text_stream('stdout')

writer = csv.DictWriter(stream, headers)
writer.writeheader()
for record in records:
writer.writerow(record)

0 comments on commit 36af9de

Please sign in to comment.