@@ -10,7 +10,7 @@ use cwl::{
1010 types:: { CWLType , DefaultValue , Directory , File } ,
1111} ;
1212use glob:: glob;
13- use serde_yaml:: Value ;
13+ use serde_yaml:: { Mapping , Value } ;
1414use std:: {
1515 collections:: HashMap ,
1616 env,
@@ -285,7 +285,7 @@ pub fn preprocess_cwl<P: AsRef<Path>>(contents: &str, path: P) -> Result<String,
285285 let mut yaml: Value = serde_yaml:: from_str ( contents) ?;
286286 let path = path. as_ref ( ) . parent ( ) . unwrap_or_else ( || Path :: new ( "." ) ) ;
287287 resolve_imports ( & mut yaml, path) ?;
288-
288+ resolve_shortcuts ( & mut yaml ) ;
289289 Ok ( serde_yaml:: to_string ( & yaml) ?)
290290}
291291
@@ -316,6 +316,50 @@ fn resolve_imports(value: &mut Value, base_path: &Path) -> Result<(), Box<dyn Er
316316 Ok ( ( ) )
317317}
318318
319+ fn resolve_shortcuts ( value : & mut Value ) {
320+ //get inputs block
321+ let mut stdin_id: Option < String > = None ;
322+ if let Value :: Mapping ( cwl) = value {
323+ let inputs = cwl. get_mut ( "inputs" ) . unwrap ( ) ; //block is mandatory!
324+ if let Value :: Mapping ( map) = inputs {
325+ for ( id, map_val) in map {
326+ //if shortcut of shortcut expand first time
327+ if map_val == & Value :: String ( "stdin" . to_string ( ) ) {
328+ let mut mapping = Mapping :: new ( ) ;
329+ mapping. insert ( Value :: String ( "type" . to_string ( ) ) , Value :: String ( "stdin" . to_string ( ) ) ) ;
330+ * map_val = Value :: Mapping ( mapping) ;
331+ }
332+ if let Value :: Mapping ( map_map) = map_val {
333+ process_stdin_input ( map_map, id, & mut stdin_id) ;
334+ }
335+ }
336+ } else if let Value :: Sequence ( seq) = inputs {
337+ for item in seq {
338+ if let Value :: Mapping ( map) = item {
339+ let id_val = map. get ( "id" ) . cloned ( ) . unwrap ( ) ;
340+ process_stdin_input ( map, & id_val, & mut stdin_id) ;
341+ }
342+ }
343+ }
344+
345+ if let Some ( stdin_id) = stdin_id {
346+ cwl. insert ( Value :: String ( "stdin" . to_string ( ) ) , Value :: String ( format ! ( "$(inputs.{stdin_id}.path)" ) ) ) ;
347+ }
348+ }
349+ }
350+
351+ fn process_stdin_input ( map : & mut Mapping , id : & Value , stdin_id : & mut Option < String > ) {
352+ if let Some ( Value :: String ( type_str) ) = map. get_mut ( Value :: String ( "type" . to_string ( ) ) ) {
353+ if type_str == "stdin" {
354+ * type_str = "File" . to_string ( ) ;
355+ map. insert ( Value :: String ( "streamable" . to_string ( ) ) , Value :: Bool ( true ) ) ;
356+ if let Value :: String ( id_str) = id {
357+ * stdin_id = Some ( id_str. clone ( ) ) ;
358+ }
359+ }
360+ }
361+ }
362+
319363pub fn is_docker_installed ( ) -> bool {
320364 let output = Command :: new ( "docker" ) . arg ( "--version" ) . output ( ) ;
321365
0 commit comments