-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.d
73 lines (61 loc) · 1.79 KB
/
app.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Example of cwl-d-auto
*
* Authors: Tomoya Tanjo
* Copyright: © 2022 Tomoya Tanjo
* License: Apache-2.0
*/
void main(string[] args)
{
import std : enforce, exists, getopt, stderr;
string cwlVersion = "v1.0";
auto opts = args.getopt(
"cwl-version", "CWL loader", &cwlVersion,
);
if (opts.helpWanted || args.length != 2)
{
import std : baseName, defaultGetoptFormatter, format, outdent, stdout;
immutable baseMessage = format!(q"EOS
A demonstration to use auto generated CWL parsers
Usage: %s [options] [cwlfile]
EOS".outdent[0 .. $ - 1])(args[0].baseName);
defaultGetoptFormatter(
stdout.lockingTextWriter, baseMessage,
opts.options, "%-*s %-*s%*s%s\x0a",
);
return;
}
auto file = args[1];
enforce(file.exists, "File not found");
switch(cwlVersion)
{
case "v1.0":{
import cwl.v1_0;
import salad.resolver : absoluteURI;
import dyaml : Node;
import std : match, tryMatch, writefln;
// Loading file
auto uri = file.absoluteURI;
// dispatch with std.sumtype.match for loaded object
auto doc = importFromURI(uri).match!(
// typical case
(DocumentRootType r) => r,
// When loaded CWL has `$graph`, the result is DocumentRootType[]
(DocumentRootType[] rs) => rs[0],
);
// use std.sumtype.tryMatch if you can assume the type of target object
// The following `tryMatch` assumes `doc` is CLT or Workflow. Otherwise it throws an exception
auto classStr = doc.tryMatch!(
(CommandLineTool clt) => "CommandLineTool",
(Workflow wf) => "Workflow",
);
writefln!"%s is %s class."(uri, classStr);
// Convert CWL object to YAML node
auto yamlNode = doc.match!(d => Node(d));
break;
}
default:
stderr.writefln!"Example is not yet prepared: %s"(cwlVersion);
return;
}
}