Skip to content

Commit 30b294c

Browse files
committed
feat(Pipeline): Add version
Used to specify a version, get the value with --version, and output in the interface JSON for a consistent version across bindgen packages.
1 parent 02d8bbe commit 30b294c

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

include/itkPipeline.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
(pipeline).interface_json(); \
5151
std::exit(0); \
5252
} \
53+
if (arg == "--version") \
54+
{ \
55+
std::cout << "Version: " << (pipeline).get_version() << std::endl; \
56+
std::exit(0); \
57+
} \
5358
} \
5459
(pipeline).parse(); \
5560
} catch(const CLI::ParseError &e) { \
@@ -159,13 +164,24 @@ class WebAssemblyInterface_EXPORT Pipeline: public CLI::App
159164
return m_argv;
160165
}
161166

167+
const std::string& get_version() const
168+
{
169+
return m_Version;
170+
}
171+
172+
void set_version(const char * version)
173+
{
174+
m_Version = version;
175+
}
176+
162177
void interface_json();
163178

164179
~Pipeline() override;
165180
private:
166181
static bool m_UseMemoryIO;
167182
int m_argc;
168183
char **m_argv;
184+
std::string m_Version;
169185
};
170186

171187

include/itkSupportInputImageTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ SupportInputImageTypes
106106
for (int ii = 0; ii < iwpArgc; ++ii)
107107
{
108108
const std::string arg(iwpArgv[ii]);
109-
if (arg == "-h" || arg == "--help" || arg == "--interface-json")
109+
if (arg == "-h" || arg == "--help" || arg == "--interface-json" || arg == "--version")
110110
{
111111
passThrough = true;
112112
}

include/itkSupportInputMeshTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ SupportInputMeshTypes
108108
for (int ii = 0; ii < iwpArgc; ++ii)
109109
{
110110
const std::string arg(iwpArgv[ii]);
111-
if (arg == "-h" || arg == "--help" || arg == "--interface-json")
111+
if (arg == "-h" || arg == "--help" || arg == "--interface-json" || arg == "--version")
112112
{
113113
passThrough = true;
114114
}

include/itkSupportInputPolyDataTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ SupportInputPolyDataTypes
103103
for (int ii = 0; ii < iwpArgc; ++ii)
104104
{
105105
const std::string arg(iwpArgv[ii]);
106-
if (arg == "-h" || arg == "--help" || arg == "--interface-json")
106+
if (arg == "-h" || arg == "--help" || arg == "--interface-json" || arg == "--version")
107107
{
108108
passThrough = true;
109109
}

src/itkPipeline.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ Pipeline
3333
::Pipeline(std::string name, std::string description, int argc, char **argv):
3434
App(description, name),
3535
m_argc(argc),
36-
m_argv(argv)
36+
m_argv(argv),
37+
m_Version("0.1.0")
3738
{
3839
this->footer("Enjoy ITK!");
3940

4041
this->positionals_at_end(false);
4142

4243
this->add_flag("--memory-io", m_UseMemoryIO, "Use itk-wasm memory IO")->group("");
44+
this->add_flag("--version", m_Version, "Output pipeline version")->group("");
45+
4346
// Set m_UseMemoryIO before it is used by other memory parsers
4447
this->preparse_callback([this](size_t arg)
4548
{
@@ -295,6 +298,10 @@ ::interface_json()
295298
name.SetString(this->get_name().c_str(), allocator);
296299
document.AddMember("name", name.Move(), allocator);
297300

301+
rapidjson::Value version;
302+
version.SetString(this->get_version().c_str(), allocator);
303+
document.AddMember("version", version.Move(), allocator);
304+
298305
rapidjson::Value inputs(rapidjson::kArrayType);
299306
rapidjson::Value outputs(rapidjson::kArrayType);
300307
rapidjson::Value parameters(rapidjson::kArrayType);

test/itkPipelineTest.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ int
3636
itkPipelineTest(int argc, char * argv[])
3737
{
3838
itk::wasm::Pipeline pipeline("pipeline-test", "A test ITK Wasm Pipeline", argc, argv);
39+
pipeline.set_version("10.8.1");
3940

4041
std::string example_string_option = "default";
4142
pipeline.add_option("-s,--string", example_string_option, "A help string");

0 commit comments

Comments
 (0)