Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc/improved example #3

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ regen_parser: cwl_v1_*.h

## tests : compile and run the tests
tests: FORCE cwl_output_example
@result="$(shell ./cwl_output_example | md5sum)" ; \
expected="917791e054e1703bd42b181154b885d7 -" ;\
@result="$(shell ./cwl_output_example | md5sum -b)" ; \
expected="$(shell cat expected_cwl.cwl | md5sum -b)" ; \
if [ "$$result" = "$$expected" ] ; \
then echo test passed ; \
else echo test failed $$result != $$expected; exit 1; \
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# cwl-cpp-auto

Autogenerated classes for reading CWL files using the C++ language.

It Provides following features:
- Support CWL v1.2 documents
- Store CWL to YAML nodes


## How to use
The [cwl_v1.2.h](cwl_v1.2.h) header was generated using schema salad code generator applied to the CWL specification.
It is a single header and can be copied into your own project for any usage.

The usage can be seen in the [cwl_output_example.cpp](cwl_output_example.cpp) file, which show cases on how to describe your tools.
119 changes: 91 additions & 28 deletions cwl_output_example.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,107 @@
#include "cwl_v1_2.h"

#include <iostream>

using namespace https___w3id_org_cwl_cwl;
// using shortened cwl:: namespace instead of https___w3id_org_cwl_cwl
namespace cwl = https___w3id_org_cwl_cwl;

int main() {
auto tool = CommandLineTool{};
*tool.cwlVersion = CWLVersion::v1_2;
*tool.id = "Some id";
*tool.label = "some label";
*tool.doc = "documentation that is brief";
*tool.stdout_ = "log.txt";
// declaring information about this tool in general
auto tool = cwl::CommandLineTool{};
tool.cwlVersion = cwl::CWLVersion::v1_2;
tool.id = "Some id";
tool.label = "some label";
tool.doc = "documentation that is brief";
tool.stdout_ = "log.txt";

{
// Demonstrates a binding to `--first-option <SOMENUMBER>`.
// It will be exposed as `--firstOption <SOMENUMBER>`.
auto input = cwl::CommandInputParameter{};
input.id = "firstOption";
input.type = cwl::CWLType::long_;

auto binding = cwl::CommandLineBinding{};
binding.prefix = "--first-option";
input.inputBinding = binding;

tool.inputs->push_back(input);
}
{
// Demonstrates a binding to `--input-file <FILE>`.
// It will be exposed as `--inputFile <FILE>`
auto input = cwl::CommandInputParameter{};
input.id = "inputFile";
input.type = cwl::CWLType::File;

auto binding = cwl::CommandLineBinding{};
binding.prefix = "--input-file";
input.inputBinding = binding;

tool.inputs->push_back(input);
}
{
// Demonstrates output binding to `--output-file <FILE>`
// The exposed parameter is `--outputFile <FILE>`.
//
// This works in two steps:
// 1. We register a option that can be set by the user
auto input = cwl::CommandInputParameter{};
input.id = "outputFile";
input.type = cwl::CWLType::string;

auto binding = cwl::CommandLineBinding{};
binding.prefix = "--output-file";
input.inputBinding = binding;

tool.inputs->push_back(input);

// 2. We use the input value to declare that we will
// write a file there
auto output = cwl::CommandOutputParameter{};
output.id = "outputFile";
output.type = cwl::CWLType::File;

auto outputBinding = cwl::CommandOutputBinding{};
// the 'outupt-file' referes to the id of our CommandInputParameter
outputBinding.glob = "$(inputs.outputFile)";

output.outputBinding = outputBinding;

{
auto input = CommandInputParameter{};
*input.id = "first";
auto record = CommandInputRecordSchema{};
tool.outputs->push_back(output);
}
{
// Demonstrates a record with a single field `species`
// the `species` field can have the values `homo_sapiens`,
// `mus_musculus` or just be null.
// It will be exposed as `--speciesSelection.species [homo_sapiens|mus_musculus]`
auto input = cwl::CommandInputParameter{};
input.id = "speciesSelection";
auto record = cwl::CommandInputRecordSchema{};

auto fieldEntry = CommandInputRecordField{};
*fieldEntry.name = "species";
auto fieldEntry = cwl::CommandInputRecordField{};
*fieldEntry.name = "species";

auto species = CommandInputEnumSchema{};
species.symbols->push_back("homo_sapiens");
species.symbols->push_back("mus_musculus");
auto species = cwl::CommandInputEnumSchema{};
species.symbols->push_back("homo_sapiens");
species.symbols->push_back("mus_musculus");

using ListType = std::vector<std::variant<CWLType, CommandInputRecordSchema, CommandInputEnumSchema, CommandInputArraySchema, std::string>>;
*fieldEntry.type = ListType{species, "null"};
using ListType = std::vector<std::variant<cwl::CWLType, cwl::CommandInputRecordSchema, cwl::CommandInputEnumSchema, cwl::CommandInputArraySchema, std::string>>;
fieldEntry.type = ListType{species, "null"};

using ListType2 = std::vector<CommandInputRecordField>;
*record.fields = ListType2{fieldEntry};
using ListType2 = std::vector<cwl::CommandInputRecordField>;
record.fields = ListType2{fieldEntry};

using ListType3 = std::vector<std::variant<CWLType, CommandInputRecordSchema, CommandInputEnumSchema, CommandInputArraySchema, std::string>>;
*input.type = ListType3{record};
using ListType3 = std::vector<std::variant<cwl::CWLType, cwl::CommandInputRecordSchema, cwl::CommandInputEnumSchema, cwl::CommandInputArraySchema, std::string>>;
input.type = ListType3{record};

tool.inputs->push_back(input);
}
tool.inputs->push_back(input);
}


auto y = toYaml(tool);
auto y = toYaml(tool);

YAML::Emitter out;
out << y;
std::cout << out.c_str() << "\n";
YAML::Emitter out;
out << y;
std::cout << out.c_str() << "\n";
}
35 changes: 35 additions & 0 deletions expected_cwl.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
id: Some id
label: some label
doc: documentation that is brief
inputs:
firstOption:
type: long
inputBinding:
prefix: --first-option
inputFile:
type: File
inputBinding:
prefix: --input-file
outputFile:
type: string
inputBinding:
prefix: --output-file
speciesSelection:
type:
- fields:
species:
type:
- symbols:
- homo_sapiens
- mus_musculus
type: enum
- "null"
type: record
outputs:
outputFile:
type: File
outputBinding:
glob: $(inputs.outputFile)
cwlVersion: v1.2
class: CommandLineTool
stdout: log.txt