Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/common-workflow-lab/cwl-d-auto

Autogenerated classes for reading and writing CWL objects using the D language
https://github.com/common-workflow-lab/cwl-d-auto

commonwl cwl dlang parser

Last synced: 21 days ago
JSON representation

Autogenerated classes for reading and writing CWL objects using the D language

Awesome Lists containing this project

README

        

# cwl-d-auto

[![build](https://github.com/common-workflow-lab/cwl-d-auto/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/common-workflow-lab/cwl-d-auto/actions/workflows/ci.yml) [![license](https://badgen.net/github/license/common-workflow-lab/cwl-d-auto)](https://github.com/common-workflow-lab/cwl-d-auto/blob/main/LICENSE) [![code.dlang.org](https://img.shields.io/dub/v/cwl-d.svg)](https://code.dlang.org/packages/cwl-d)

Autogenerated classes for reading and writing CWL objects using the D language.

It integrates with [schema-salad-d](https://github.com/tom-tan/schema-salad-d) and provides the following features:

- Support all the CWL v1.0, v1.1 and v1.2 documents
- Load YAML files and nodes to generate corresponding D objects
- Store D object for CWL to YAML nodes

## How is the parser generated?
Each parser is generated with [schema-salad-tool](https://github.com/common-workflow-language/schema_salad) as shown below.

- CWL v1.0
```console
$ schema-salad-tool --codegen dlang https://github.com/common-workflow-language/common-workflow-language/raw/codegen/v1.0/CommonWorkflowLanguage.yml --codegen-package cwl.v1_0 --codegen-parser-info "CWL v1.0 parser generated with schema-salad-tool" --codegen-examples resources/cwl-v1.0 > v1_0.d
```

- CWL v1.1
```console
$ schema-salad-tool --codegen dlang https://github.com/common-workflow-language/cwl-v1.1/raw/codegen/CommonWorkflowLanguage.yml --codegen-package cwl.v1_1 --codegen-parser-info "CWL v1.1 parser generated with schema-salad-tool" --codegen-examples resources/cwl-v1.1 > v1_1.d
```

- CWL v1.2
```console
$ schema-salad-tool --codegen dlang https://github.com/common-workflow-language/cwl-v1.2/raw/codegen/CommonWorkflowLanguage.yml --codegen-package cwl.v1_2 --codegen-parser-info "CWL v1.2 parser generated with schema-salad-tool" --codegen-examples resources/cwl-v1.2 > v1_2.d
```

- You can specify the package name via `--codegen-package`.
- You can add informative message into the generated package via `--codegen-parser-info`. It can be accessed via `cwl.v1_2.parserInfo`.

## How to use

See [source/app.d](source/app.d) for a concrete example.

```d
import cwl.v1_0; // auto generated CWL parser
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));
```

### How to run the example
The example just prints the document class of a given CWL document.

```console
$ dub run -c demo -- resources/cwl-v1.0/valid_rename.cwl
...
Running cwl-d-auto resources/cwl-v1.0/valid_rename.cwl
file:///workspaces/cwl-d-auto/resources/cwl-v1.0/valid_rename.cwl is CommandLineTool class.
```

## How to test
It checks that CWL documents in [`resources`](resources) can be loaded with parsers in [`source/cwl`](source/cwl_d_auto).
```console
$ dub test
```