Skip to content

Commit

Permalink
feature(cli) Add --ergo option to CLI validing data for Ergo
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <jeromesimeon@me.com>
  • Loading branch information
jeromesimeon committed Apr 13, 2021
1 parent c751564 commit 1b7553d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/concerto-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ require('yargs')
type: 'boolean',
default: false
});
yargs.option('ergo', {
describe: 'validation and emit for Ergo',
type: 'boolean',
default: false
});
}, (argv) => {
if (argv.verbose) {
Logger.info(`validate ${argv.input} against the models ${argv.model}`);
Expand All @@ -53,7 +58,8 @@ require('yargs')
argv = Commands.validateValidateArgs(argv);
const options = {};
options.offline = argv.offline;
options.functional = argv.functional;
options.functional = !argv.ergo && argv.functional; // XXX Ergo option takes priority
options.ergo = argv.ergo;
return Commands.validate(argv.input, argv.model, options)
.then((result) => {
Logger.info('Input is valid');
Expand Down
2 changes: 1 addition & 1 deletion packages/concerto-cli/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Commands {
const serializer = new Serializer(factory, modelManager);

const object = serializer.fromJSON(json);
return JSON.stringify(serializer.toJSON(object));
return JSON.stringify(serializer.toJSON(object, {ergo: options.ergo}));
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/concerto-core/lib/serializer/jsongenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class JSONGenerator {
if (!Util.isNull(value)) {
parameters.stack.push(value);
result[property.getName()] = property.accept(this, parameters);
} else if (this.ergo) {
result[property.getName()] = { '$right' : null };
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/concerto-core/test/1.0.0/data/optional1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$class": "org.test.C",
"i": 42
}
4 changes: 4 additions & 0 deletions packages/concerto-core/test/1.0.0/data/optional1b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$class": "org.test.C",
"i": null
}
5 changes: 5 additions & 0 deletions packages/concerto-core/test/1.0.0/models/optional1.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace org.test

concept C {
o Integer i optional
}

0 comments on commit 1b7553d

Please sign in to comment.