forked from devongovett/protobuf-jsonschema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·22 lines (19 loc) · 801 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env node
var commander = require('commander');
var compile = require('./');
var yaml = require('js-yaml');
commander
.version(require('./package.json').version)
.arguments('<file> [model]')
.option('-f, --format [format]', 'output format: json or yaml [json]', 'json')
.option('-a, --allow [allow]', 'allow additional properties: true or false', 'true')
.action(function(file, model) {
var format = commander.format || 'json';
var opts = { allow_additional_props : !(commander.allow == 'false') };
var result = compile(opts, file, model);
if (format === 'json')
process.stdout.write(JSON.stringify(result, false, 2) + '\n');
else if (format === 'yaml')
process.stdout.write(yaml.dump(result, { noRefs: true }));
})
.parse(process.argv);