Compare commits

...

2 Commits

Author SHA1 Message Date
Timmy Welch
de3a9352ea Allow reading cli metadata from a file 2024-04-12 14:10:21 -07:00
Timmy Welch
d104ae1e8e Update help message for the -m option 2024-04-11 15:46:29 -07:00
2 changed files with 6 additions and 1 deletions

View File

@ -109,7 +109,7 @@ def register_runtime(parser: settngs.Manager) -> None:
"--metadata",
default=GenericMetadata(),
type=parse_metadata_from_string,
help="""Explicitly define, as a list, some tags to be used. e.g.:\n"series=Plastic Man, publisher=Quality Comics"\n"series=Kickers^, Inc., issue=1, year=1986"\nName-Value pairs are comma separated. Use a\n"^" to escape an "=" or a ",", as shown in\nthe example above. Some names that can be\nused: series, issue, issue_count, year,\npublisher, title\n\n""",
help="""Explicitly define some tags to be used in YAML syntax. Use @file.yaml to read from a file. e.g.:\n"series: Plastic Man, publisher: Quality Comics, year: "\n"series: 'Kickers, Inc.', issue: '1', year: 1986"\nIf you want to erase a tag leave the value blank.\nSome names that can be used: series, issue, issue_count, year,\npublisher, title\n\n""",
file=False,
)
parser.add_setting(

View File

@ -203,6 +203,11 @@ def parse_metadata_from_string(mdstr: str) -> GenericMetadata:
if not mdstr:
return md
if mdstr[0] == "@":
p = pathlib.Path(mdstr[1:])
if not p.is_file():
raise argparse.ArgumentTypeError("Invalid filepath")
mdstr = p.read_text()
if mdstr[0] != "{":
mdstr = "{" + mdstr + "}"