UI for Zipcoin Blue

command.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const validators_1 = require("./validators");
  5. class Command {
  6. validate(inputs) {
  7. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  8. validateInputs(inputs, this.metadata);
  9. });
  10. }
  11. }
  12. exports.Command = Command;
  13. function validateInputs(argv, metadata) {
  14. if (!metadata.inputs) {
  15. return;
  16. }
  17. const errors = [];
  18. for (let i in metadata.inputs) {
  19. const input = metadata.inputs[i];
  20. if (input.validators && input.validators.length > 0) {
  21. const vnames = input.validators.map(v => v.name);
  22. if (vnames.includes('required')) {
  23. validators_1.validate(argv[i], input.name, [validators_1.validators.required], errors);
  24. }
  25. else {
  26. if (argv[i]) {
  27. validators_1.validate(argv[i], input.name, input.validators, errors);
  28. }
  29. }
  30. }
  31. }
  32. if (errors.length > 0) {
  33. throw errors;
  34. }
  35. }
  36. exports.validateInputs = validateInputs;