From 2086bb916cc8d03c2e820188370be40ebd5bfac5 Mon Sep 17 00:00:00 2001 From: Mike Lin Date: Wed, 1 May 2024 11:35:49 -1000 Subject: [PATCH] CLI: allow compound inputs as JSON (#688) --- WDL/CLI.py | 10 ++++++++++ tests/runner.t | 6 +----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/WDL/CLI.py b/WDL/CLI.py index 7233ae85..dc51d14f 100644 --- a/WDL/CLI.py +++ b/WDL/CLI.py @@ -1260,6 +1260,16 @@ def runner_input_value(s_value, ty, downloadable, root): return Value.Array( ty.item_type, [runner_input_value(s_value, ty.item_type, downloadable, root)] ) + if isinstance(ty, (Type.Pair, Type.Map, Type.StructInstance)): + # parse JSON for compound types + try: + return Value.from_json(ty, json.loads(s_value)) + except json.JSONDecodeError as exn: + raise Error.InputError( + "Invalid JSON for input of type {}, check syntax and shell quoting: {}".format( + str(ty), exn + ) + ) if isinstance(ty, Type.Any): # infer dynamically-typed runtime overrides try: diff --git a/tests/runner.t b/tests/runner.t index 4f785a07..08645683 100644 --- a/tests/runner.t +++ b/tests/runner.t @@ -621,9 +621,5 @@ task test_task { >>> } EOF -$miniwdl run issue686.wdl -i '{ - "read_group": { - "ID": "test" - } -}' +$miniwdl run issue686.wdl read_group='{"ID":"test"}' is "$?" "0" "ensure optional fields in structs initialized from JSON (issue 686 regression)"