Skip to content

Commit 48e8afd

Browse files
author
Peter Amstutz
committed
Add input_required flag to main().
When false, command line parameters that provide workflow inputs are always optional. This makes it possible to pass the executor an incomplete input object. This is desirable if the executor is going to do something other than run the workflow.
1 parent 665141f commit 48e8afd

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

cwltool/argparser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,16 @@ class DirectoryAppendAction(FSAppendAction):
390390

391391

392392
def add_argument(toolparser, name, inptype, records, description="",
393-
default=None):
393+
default=None, input_required=True):
394394
# type: (argparse.ArgumentParser, Text, Any, List[Text], Text, Any) -> None
395395
if len(name) == 1:
396396
flag = "-"
397397
else:
398398
flag = "--"
399399

400-
required = default is None
400+
# if input_required is false, don't make the command line
401+
# parameter required.
402+
required = default is None and input_required
401403
if isinstance(inptype, MutableSequence):
402404
if inptype[0] == "null":
403405
required = False
@@ -458,7 +460,7 @@ def add_argument(toolparser, name, inptype, records, description="",
458460
default=default, **typekw)
459461

460462

461-
def generate_parser(toolparser, tool, namemap, records):
463+
def generate_parser(toolparser, tool, namemap, records, input_required=True):
462464
# type: (argparse.ArgumentParser, Process, Dict[Text, Text], List[Text]) -> argparse.ArgumentParser
463465
toolparser.add_argument("job_order", nargs="?", help="Job input json file")
464466
namemap["job_order"] = "job_order"
@@ -469,6 +471,6 @@ def generate_parser(toolparser, tool, namemap, records):
469471
inptype = inp["type"]
470472
description = inp.get("doc", "")
471473
default = inp.get("default", None)
472-
add_argument(toolparser, name, inptype, records, description, default)
474+
add_argument(toolparser, name, inptype, records, description, default, input_required)
473475

474476
return toolparser

cwltool/main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,15 @@ def init_job_order(job_order_object, # type: Optional[MutableMapping[Text
281281
relative_deps=False, # type: bool
282282
make_fs_access=StdFsAccess, # type: Callable[[Text], StdFsAccess]
283283
input_basedir="", # type: Text
284-
secret_store=None # type: SecretStore
284+
secret_store=None, # type: SecretStore
285+
input_required=True # type: bool
285286
): # type: (...) -> MutableMapping[Text, Any]
286287
secrets_req, _ = process.get_requirement("http://commonwl.org/cwltool#Secrets")
287288
if job_order_object is None:
288289
namemap = {} # type: Dict[Text, Text]
289290
records = [] # type: List[Text]
290291
toolparser = generate_parser(
291-
argparse.ArgumentParser(prog=args.workflow), process, namemap, records)
292+
argparse.ArgumentParser(prog=args.workflow), process, namemap, records, input_required)
292293
if args.tool_help:
293294
toolparser.print_help()
294295
exit(0)
@@ -485,7 +486,8 @@ def main(argsl=None, # type: List[str]
485486
custom_schema_callback=None, # type: Callable[[], None]
486487
executor=None, # type: Callable[..., Tuple[Dict[Text, Any], Text]]
487488
loadingContext=None, # type: LoadingContext
488-
runtimeContext=None # type: RuntimeContext
489+
runtimeContext=None, # type: RuntimeContext
490+
input_required=True # type: bool
489491
): # type: (...) -> int
490492
if not stdout: # force UTF-8 even if the console is configured differently
491493
if (hasattr(sys.stdout, "encoding") # type: ignore
@@ -789,7 +791,8 @@ def my_represent_none(self, data): # pylint: disable=unused-argument
789791
relative_deps=args.relative_deps,
790792
make_fs_access=runtimeContext.make_fs_access,
791793
input_basedir=input_basedir,
792-
secret_store=runtimeContext.secret_store)
794+
secret_store=runtimeContext.secret_store,
795+
input_required=input_required)
793796
except SystemExit as err:
794797
return err.code
795798

0 commit comments

Comments
 (0)