Skip to content

Commit

Permalink
fixed --parameters parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jake authored and jake committed Nov 6, 2024
1 parent 054f029 commit 458eb24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions internetarchive/cli/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,18 @@ def validate_identifier(identifier):
return identifier


def prepare_args_dict(args, parser, arg_type="metadata", many=False):
def prepare_args_dict(args, parser, arg_type="metadata", many=False, query_string=False):
if not args:
return {}
try:
if many:
return get_args_dict_many_write([item for sublist in args for item in sublist])
else:
if isinstance(args[0], list):
return get_args_dict([item for sublist in args for item in sublist])
return get_args_dict([item for sublist in args for item in sublist],
query_string=True)
else:
return get_args_dict(args)
return get_args_dict(args, query_string=True)
except ValueError as e:
parser.error(f"--{arg_type} must be formatted as --{arg_type}='key:value'")

Expand Down
9 changes: 7 additions & 2 deletions internetarchive/cli/ia_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,13 @@ def main(args: argparse.Namespace, parser: argparse.ArgumentParser) -> None:
"""
try:
# Validate args.
args.parameters = prepare_args_dict(args.parameters, parser=parser)
args.header = prepare_args_dict(args.header, parser=parser)
args.parameters = prepare_args_dict(args.parameters,
parser=parser,
arg_type='parameters',
query_string=True)
args.header = prepare_args_dict(args.header,
parser=parser,
arg_type='header')

# Prepare fields and sorts.
fields = prepare_values(args.field)
Expand Down

0 comments on commit 458eb24

Please sign in to comment.