UNPKG

@jil/args

Version:

A convention based argument parsing and formatting library, with strict validation checks

42 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Scope = void 0; const castValue_1 = require("./utils/castValue"); const formatValue_1 = require("./utils/formatValue"); class Scope { constructor(name, config) { this.negated = false; this.unknown = false; this.name = name; if (config) { this.config = config; } else { this.config = { description: '', type: 'string' }; this.unknown = true; } } get flag() { return this.config.type === 'boolean'; } get finalValue() { return (0, formatValue_1.formatValue)((0, castValue_1.castValue)(this.value, this.config.type), this.config.format); } captureValue(value, commit) { const { config } = this; // Update the scope with this new value if (config.multiple) { this.value.push(value); } else { this.value = value; } // Commit scope when a single value is set, // or when a multiple arity is met. if (!config.multiple || (config.arity && Array.isArray(this.value) && this.value.length >= config.arity)) { commit(); } } } exports.Scope = Scope; //# sourceMappingURL=Scope.js.map