@@ -478,6 +478,11 @@ module Encode =
478478 | Some workflow -> encodeWorkflowDescriptionElement workflow
479479 | None ->
480480 raise ( System.ArgumentException( $" RunWorkflow must contain CWLWorkflowDescription but got %A {workflowObj}" ))
481+ | RunExpressionTool expressionToolObj ->
482+ match WorkflowStepRunOps.tryGetExpressionTool run with
483+ | Some expressionTool -> encodeExpressionToolDescriptionElement expressionTool
484+ | None ->
485+ raise ( System.ArgumentException( $" RunExpressionTool must contain CWLExpressionToolDescription but got %A {expressionToolObj}" ))
481486
482487 and encodeToolDescriptionElement ( td : CWLToolDescription ) : YAMLElement =
483488 let basePairs =
@@ -525,6 +530,49 @@ module Encode =
525530 | None -> withOutputs
526531 yMap withMetadata
527532
533+ and encodeExpressionToolDescriptionElement ( et : CWLExpressionToolDescription ) : YAMLElement =
534+ let basePairs =
535+ [ " cwlVersion" , Encode.string et.CWLVersion
536+ " class" , Encode.string " ExpressionTool" ]
537+ |> appendOptPair ( et.Label |> Option.map encodeLabel)
538+ |> appendOptPair ( et.Doc |> Option.map encodeDoc)
539+ let withHints =
540+ match et.Hints with
541+ | Some h when h.Count > 0 ->
542+ basePairs @ [ " hints" , ( h |> Seq.map encodeRequirement |> List.ofSeq |> YAMLElement.Sequence) ]
543+ | _ -> basePairs
544+ let withRequirements =
545+ match et.Requirements with
546+ | Some r when r.Count > 0 ->
547+ withHints @ [ " requirements" , ( r |> Seq.map encodeRequirement |> List.ofSeq |> YAMLElement.Sequence) ]
548+ | _ -> withHints
549+ let withInputs =
550+ match et.Inputs with
551+ | Some i when i.Count > 0 ->
552+ withRequirements @ [ " inputs" , ( i |> Seq.map encodeCWLInput |> Seq.toList |> yMap) ]
553+ | _ -> withRequirements
554+ let withOutputs =
555+ withInputs @ [ " outputs" , ( et.Outputs |> Seq.map encodeCWLOutput |> Seq.toList |> yMap) ]
556+ let withExpression =
557+ withOutputs @ [ " expression" , Encode.string et.Expression ]
558+ let withMetadata =
559+ match et.Metadata with
560+ | Some md ->
561+ md.GetProperties( false )
562+ |> Seq.fold ( fun acc kvp ->
563+ let encodedValue =
564+ match kvp.Value with
565+ | :? string as s -> Encode.string s
566+ | :? bool as b -> yBool b
567+ | :? int as i -> Encode.int i
568+ | :? float as f -> Encode.float f
569+ | :? YAMLElement as y -> y
570+ | _ -> Encode.string ( string kvp.Value)
571+ acc @ [ kvp.Key, encodedValue ]
572+ ) withExpression
573+ | None -> withExpression
574+ yMap withMetadata
575+
528576 and encodeWorkflowDescriptionElement ( wd : CWLWorkflowDescription ) : YAMLElement =
529577 let basePairs =
530578 [ " cwlVersion" , Encode.string wd.CWLVersion
@@ -653,11 +701,16 @@ module Encode =
653701 encodeWorkflowDescriptionElement wd
654702 |> renderTopLevelElement [ " cwlVersion" ; " class" ; " label" ; " doc" ] [ " hints" ; " requirements" ; " inputs" ; " steps" ; " outputs" ]
655703
704+ let encodeExpressionToolDescription ( et : CWLExpressionToolDescription ) : string =
705+ encodeExpressionToolDescriptionElement et
706+ |> renderTopLevelElement [ " cwlVersion" ; " class" ; " label" ; " doc" ] [ " hints" ; " requirements" ; " inputs" ; " outputs" ; " expression" ]
707+
656708
657709 let encodeProcessingUnit ( pu : CWLProcessingUnit ) : string =
658710 match pu with
659711 | CommandLineTool td -> encodeToolDescription td
660712 | Workflow wd -> encodeWorkflowDescription wd
713+ | ExpressionTool et -> encodeExpressionToolDescription et
661714
662715 /// Encode a CWLType to a single-line YAML string using flow/inline style
663716 /// This produces YAML that doesn't contain newlines and can be embedded in JSON
0 commit comments