Skip to content

Commit dffddeb

Browse files
committed
preprocess stdin shortcut
1 parent fe6f677 commit dffddeb

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## 🐛 Bugfixes
66
- fixed a bug with Dockerfile path resolution
77
- handle NetworkAccess Requirment in runner
8-
- ramping up runner conformance from 160/378 to 163/378
8+
- ramping up runner conformance from 160/378 to 164/378
99

1010
# v0.5.2
1111
## 🐛 Bugfixes

crates/cwl-execution/src/util.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use cwl::{
1010
types::{CWLType, DefaultValue, Directory, File},
1111
};
1212
use glob::glob;
13-
use serde_yaml::Value;
13+
use serde_yaml::{Mapping, Value};
1414
use 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+
319363
pub fn is_docker_installed() -> bool {
320364
let output = Command::new("docker").arg("--version").output();
321365

crates/cwl/src/inputs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub struct CommandInputParameter {
2121
#[serde(default)]
2222
#[serde(skip_serializing_if = "<&bool>::not")]
2323
pub load_contents: bool,
24+
#[serde(default)]
25+
#[serde(skip_serializing_if = "<&bool>::not")]
26+
pub streamable: bool,
2427
}
2528

2629
impl CommandInputParameter {

0 commit comments

Comments
 (0)