Skip to content

Commit

Permalink
allow passing of labels for ocm append
Browse files Browse the repository at this point in the history
Accept optional labels to be injected into artefacts. This is convenient
for (shell-)scripts as handling special-cases (single label vs.
multiple labels) is quite cumbersome.
  • Loading branch information
ccwienk committed Jan 13, 2025
1 parent 6efaf1e commit b6c995a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ocm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,30 @@ def append(parsed):
else:
obj = json.load(sys.stdin)

if not (labels := parsed.labels):
labels = []
else:
labels = [dataclasses.asdict(l) for l in _iter_parsed_labels(labels=labels)]

def inject_labels(artefact: dict, labels):
if not 'labels' in artefact:
artefact['labels'] = []

artefact['labels'] = labels

if isinstance(obj, list):
for o in obj:
inject_labels(
artefact=o,
labels=labels,
)

attr.extend(obj)
else:
inject_labels(
artefact=obj,
labels=labels,
)
attr.append(obj)

with open(parsed.file, 'w') as f:
Expand Down Expand Up @@ -230,6 +251,13 @@ def main():
)
add_parser.add_argument('type', choices=('r', 'resource', 's', 'source'))
add_parser.add_argument('--file', '-f', required=True)
add_parser.add_argument(
'--label',
dest='labels',
action='append',
default=[],
help='labels to set for passed artefact (for convenience)',
)
add_parser.set_defaults(callable=append)

upload_parser = maincmd_parsers.add_parser(
Expand Down

0 comments on commit b6c995a

Please sign in to comment.