def init_job_order(job_order_object: Optional[CWLObjectType], args: argparse.Namespace, process: Process, loader: Loader, stdout: Union[(TextIO, StreamWriter)], print_input_deps: bool=False, relative_deps: str='primary', make_fs_access: Callable[([str], StdFsAccess)]=StdFsAccess, input_basedir: str='', secret_store: Optional[SecretStore]=None, input_required: bool=True, runtime_context: Optional[RuntimeContext]=None) -> CWLObjectType:
    (secrets_req, _) = process.get_requirement('http://commonwl.org/cwltool#Secrets')
    if (job_order_object is None):
        namemap = {}
        records = []
        toolparser = generate_parser(argparse.ArgumentParser(prog=args.workflow), process, namemap, records, input_required, loader.fetcher.urljoin, (file_uri(os.getcwd()) + '/'))
        if args.tool_help:
            toolparser.print_help(cast(IO[str], stdout))
            exit(0)
        cmd_line = vars(toolparser.parse_args(args.job_order))
        for record_name in records:
            record = {}
            record_items = {k: v for (k, v) in cmd_line.items() if k.startswith(record_name)}
            for (key, value) in record_items.items():
                record[key[(len(record_name) + 1):]] = value
                del cmd_line[key]
            cmd_line[str(record_name)] = record
        if (('job_order' in cmd_line) and cmd_line['job_order']):
            try:
                job_order_object = cast(CWLObjectType, loader.resolve_ref(cmd_line['job_order'])[0])
            except Exception:
                _logger.exception('Failed to resolv job_order: %s', cmd_line['job_order'])
                exit(1)
        else:
            job_order_object = {'id': args.workflow}
        del cmd_line['job_order']
        job_order_object.update({namemap[k]: v for (k, v) in cmd_line.items()})
        if (secret_store and secrets_req):
            secret_store.store([shortname(sc) for sc in cast(List[str], secrets_req['secrets'])], job_order_object)
        if _logger.isEnabledFor(logging.DEBUG):
            _logger.debug('Parsed job order from command line: %s', json_dumps(job_order_object, indent=4, default=str))
    for inp in process.tool['inputs']:
        if (('default' in inp) and ((not job_order_object) or (shortname(inp['id']) not in job_order_object))):
            if (not job_order_object):
                job_order_object = {}
            job_order_object[shortname(inp['id'])] = inp['default']

    def path_to_loc(p: CWLObjectType) -> None:
        if (('location' not in p) and ('path' in p)):
            p['location'] = p['path']
            del p['path']
    ns = {}
    ns.update(cast(ContextType, job_order_object.get('$namespaces', {})))
    ns.update(cast(ContextType, process.metadata.get('$namespaces', {})))
    ld = Loader(ns)

    def expand_formats(p: CWLObjectType) -> None:
        if ('format' in p):
            p['format'] = ld.expand_url(cast(str, p['format']), '')
    visit_class(job_order_object, ('File', 'Directory'), path_to_loc)
    visit_class(job_order_object, ('File',), functools.partial(add_sizes, make_fs_access(input_basedir)))
    visit_class(job_order_object, ('File',), expand_formats)
    adjustDirObjs(job_order_object, trim_listing)
    normalizeFilesDirs(job_order_object)
    if print_input_deps:
        if (not runtime_context):
            raise RuntimeError('runtime_context is required for print_input_deps.')
        runtime_context.toplevel = True
        builder = process._init_job(job_order_object, runtime_context)
        builder.loadListing = 'no_listing'
        builder.bind_input(process.inputs_record_schema, job_order_object, discover_secondaryFiles=True)
        basedir: Optional[str] = None
        uri = cast(str, job_order_object['id'])
        if (uri == args.workflow):
            basedir = os.path.dirname(uri)
            uri = ''
        printdeps(job_order_object, loader, stdout, relative_deps, uri, basedir=basedir, nestdirs=False)
        exit(0)
    if (secret_store and secrets_req):
        secret_store.store([shortname(sc) for sc in cast(List[str], secrets_req['secrets'])], job_order_object)
    if ('cwl:tool' in job_order_object):
        del job_order_object['cwl:tool']
    if ('id' in job_order_object):
        del job_order_object['id']
    return job_order_object
def init_job_order(job_order_object: Optional[CWLObjectType], args: argparse.Namespace, process: Process, loader: Loader, stdout: Union[(TextIO, StreamWriter)], print_input_deps: bool=False, relative_deps: str='primary', make_fs_access: Callable[([str], StdFsAccess)]=StdFsAccess, input_basedir: str=, secret_store: Optional[SecretStore]=None, input_required: bool=True, runtime_context: Optional[RuntimeContext]=None) -> CWLObjectType:
    (secrets_req, _) = process.get_requirement('http://commonwl.org/cwltool#Secrets')
    if (job_order_object is None):
        namemap = {}
        records = []
        toolparser = generate_parser(argparse.ArgumentParser(prog=args.workflow), process, namemap, records, input_required, loader.fetcher.urljoin, (file_uri(os.getcwd()) + '/'))
        if args.tool_help:
            toolparser.print_help(cast(IO[str], stdout))
            exit(0)
        cmd_line = vars(toolparser.parse_args(args.job_order))
        for record_name in records:
            record = {}
            record_items = {k: v for (k, v) in cmd_line.items() if k.startswith(record_name)}
            for (key, value) in record_items.items():
                record[key[(len(record_name) + 1):]] = value
                del cmd_line[key]
            cmd_line[str(record_name)] = record
        if (('job_order' in cmd_line) and cmd_line['job_order']):
            try:
                job_order_object = cast(CWLObjectType, loader.resolve_ref(cmd_line['job_order'])[0])
            except Exception:
                _logger.exception('Failed to resolv job_order: %s', cmd_line['job_order'])
                exit(1)
        else:
            job_order_object = {'id': args.workflow}
        del cmd_line['job_order']
        job_order_object.update({namemap[k]: v for (k, v) in cmd_line.items()})
        if (secret_store and secrets_req):
            secret_store.store([shortname(sc) for sc in cast(List[str], secrets_req['secrets'])], job_order_object)
        if _logger.isEnabledFor(logging.DEBUG):
            _logger.debug('Parsed job order from command line: %s', json_dumps(job_order_object, indent=4, default=str))
    for inp in process.tool['inputs']:
        if (('default' in inp) and ((not job_order_object) or (shortname(inp['id']) not in job_order_object))):
            if (not job_order_object):
                job_order_object = {}
            job_order_object[shortname(inp['id'])] = inp['default']

    def path_to_loc(p: CWLObjectType) -> None:
        if (('location' not in p) and ('path' in p)):
            p['location'] = p['path']
            del p['path']
    ns = {}
    ns.update(cast(ContextType, job_order_object.get('$namespaces', {})))
    ns.update(cast(ContextType, process.metadata.get('$namespaces', {})))
    ld = Loader(ns)

    def expand_formats(p: CWLObjectType) -> None:
        if ('format' in p):
            p['format'] = ld.expand_url(cast(str, p['format']), )
    visit_class(job_order_object, ('File', 'Directory'), path_to_loc)
    visit_class(job_order_object, ('File',), functools.partial(add_sizes, make_fs_access(input_basedir)))
    visit_class(job_order_object, ('File',), expand_formats)
    adjustDirObjs(job_order_object, trim_listing)
    normalizeFilesDirs(job_order_object)
    if print_input_deps:
        if (not runtime_context):
            raise RuntimeError('runtime_context is required for print_input_deps.')
        runtime_context.toplevel = True
        builder = process._init_job(job_order_object, runtime_context)
        builder.loadListing = 'no_listing'
        builder.bind_input(process.inputs_record_schema, job_order_object, discover_secondaryFiles=True)
        basedir: Optional[str] = None
        uri = cast(str, job_order_object['id'])
        if (uri == args.workflow):
            basedir = os.path.dirname(uri)
            uri = 
        printdeps(job_order_object, loader, stdout, relative_deps, uri, basedir=basedir, nestdirs=False)
        exit(0)
    if (secret_store and secrets_req):
        secret_store.store([shortname(sc) for sc in cast(List[str], secrets_req['secrets'])], job_order_object)
    if ('cwl:tool' in job_order_object):
        del job_order_object['cwl:tool']
    if ('id' in job_order_object):
        del job_order_object['id']
    return job_order_object