diff --git a/Makefile b/Makefile index c6d7f71..685323b 100644 --- a/Makefile +++ b/Makefile @@ -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; \ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e06263b --- /dev/null +++ b/README.md @@ -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. diff --git a/cwl_output_example.cpp b/cwl_output_example.cpp index b3c6dcd..99923b0 100644 --- a/cwl_output_example.cpp +++ b/cwl_output_example.cpp @@ -1,44 +1,107 @@ #include "cwl_v1_2.h" + #include -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 `. + // It will be exposed as `--firstOption `. + 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 `. + // It will be exposed as `--inputFile ` + 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 ` + // The exposed parameter is `--outputFile `. + // + // 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>; - *fieldEntry.type = ListType{species, "null"}; + using ListType = std::vector>; + fieldEntry.type = ListType{species, "null"}; - using ListType2 = std::vector; - *record.fields = ListType2{fieldEntry}; + using ListType2 = std::vector; + record.fields = ListType2{fieldEntry}; - using ListType3 = std::vector>; - *input.type = ListType3{record}; + using ListType3 = std::vector>; + 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"; } diff --git a/expected_cwl.cwl b/expected_cwl.cwl new file mode 100644 index 0000000..d0a68fe --- /dev/null +++ b/expected_cwl.cwl @@ -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