avro-schema-validator
Version:
A tool to infer AVRO schema's from JSON messages, and to validate it.
87 lines • 3.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var commandLineArgs = require("command-line-args");
var npmPackage = require("../package.json");
var getUsage = require("command-line-usage");
var parser_1 = require("./parser");
var CommandLineInterface = (function () {
function CommandLineInterface() {
}
CommandLineInterface.optionDefinitions = [
{
name: 'help',
alias: 'h',
type: Boolean,
description: 'Show help text'
},
{
name: 'file',
alias: 'f',
type: String,
defaultOption: true,
description: 'JSON or XML file that must be validated against a schema, or for which we want to infer a schema.'
},
{
name: 'schema',
alias: 's',
type: String,
description: 'The schema file which is used to validate the JSON or XML file.'
},
{
name: 'output',
alias: 'o',
type: String,
description: 'Override the default schema file name.'
},
{
name: 'wrapped',
alias: 'w',
type: Boolean,
description: 'If set, use wrapped union types.'
}
];
CommandLineInterface.sections = [
{
header: npmPackage.name + ", v" + npmPackage.version,
content: npmPackage.license + " license.\n\n " + npmPackage.description + "\n\n Use avro-schema-validator to infer an AVRO schema based on JSON or XML input,\n or validate a JSON message against a schema.\n\n In some cases, a valid JSON message may be considered invalid when wrapped\n unions are used, e.g. when you have a property 'content', whose type is\n ['int', 'float'], in JSON you would need to wrap its value in order to\n distinguish between an integer and a float. In case normal parsing fails, \n it retries the validation using the -w option (wrapped).\n "
},
{
header: 'Options',
optionList: CommandLineInterface.optionDefinitions
},
{
header: 'Examples',
content: [
{
desc: '01. Infer a cap.avsc schema from the cap.json file.',
example: '$ avro-schema-validator cap.json'
},
{
desc: '02. Infer a schema, and specify the output file.',
example: '$ avro-schema-validator cap.json -o mySchema.avsc'
},
{
desc: '03. Validate a cap.json against the cap.avsc schema.',
example: '$ avro-schema-validator cap.json -s cap.avsc'
},
{
desc: '04. Validate a wrapped cap.json against the cap.avsc schema.',
example: '$ avro-schema-validator -w cap.json -s cap.avsc'
}
]
}
];
return CommandLineInterface;
}());
exports.CommandLineInterface = CommandLineInterface;
var options = commandLineArgs(CommandLineInterface.optionDefinitions);
if (options.help || !options.file) {
var usage = getUsage(CommandLineInterface.sections);
console.log(usage);
process.exit(0);
}
else {
var parser = new parser_1.Parser(options);
parser.run();
}
//# sourceMappingURL=cli.js.map