From 95e2b93d2722fcef0cdedcd72cd316fb04a40379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Cabrera=20Dur=C3=A1n?= <pateketrueke@gmail.com> Date: Wed, 30 Oct 2019 21:45:05 -0600 Subject: [PATCH] Setup argv for CLI --- bin/gen.js | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/bin/gen.js b/bin/gen.js index 0b1c4345..ae029e03 100755 --- a/bin/gen.js +++ b/bin/gen.js @@ -6,14 +6,48 @@ const jsf = require('../dist/main.umd.js'); const sample = process.argv.slice(2)[0]; -// FIXME: setup argv.... +// FIXME: validate types on given input.... const argv = require('wargs')(process.argv.slice(2), { - boolean: 'O', + boolean: 'DXMTFOxedrJUSE', alias: { - 'always-fake-optionals': 'O', + D: 'defaultInvalidTypeProduct', + X: 'defaultRandExpMax', + + p: 'ignoreProperties', + M: 'ignoreMissingRefs', + T: 'failOnInvalidTypes', + F: 'failOnInvalidFormat', + + O: 'alwaysFakeOptionals', + o: 'optionalsProbability', + x: 'fixedProbabilities', + e: 'useExamplesValue', + d: 'useDefaultValue', + R: 'requiredOnly', + r: 'random', + + i: 'minItems', + I: 'maxItems', + l: 'minLength', + L: 'maxLength', + + J: 'resolveJsonPath', + U: 'reuseProperties', + S: 'fillProperties', + E: 'replaceEmptyByRandomValue', }, }); +if (typeof argv.flags.random === 'string') { + argv.flags.random = () => parseFloat(argv.flags.random); +} + +if (typeof argv.flags.ignoreProperties === 'string') { + argv.flags.ignoreProperties = [argv.flags.ignoreProperties]; +} + +jsf.option(argv.flags); + const { inspect } = require('util'); const { Transform } = require('stream'); const { readFileSync } = require('fs'); -- GitLab