UNPKG

@biskyjs/framework

Version:
59 lines 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlagUnorderedStrategy = void 0; const lexure_1 = require("@sapphire/lexure"); const result_1 = require("@sapphire/result"); const never = () => result_1.Option.none; const always = () => true; class FlagUnorderedStrategy extends lexure_1.PrefixedStrategy { // rome-ignore lint/correctness/noUnreachableSuper: ? constructor({ flags, options, prefixes = ["--", "-", "—"], separators = ["=", ":"] } = {}) { super(prefixes, separators); Object.defineProperty(this, "flags", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "options", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.flags = flags || []; this.options = options || []; if (this.flags === true) this.allowedFlag = always; else if (this.flags.length === 0) this.matchFlag = never; if (this.options === true) { this.allowedOption = always; } else if (this.options.length === 0) { this.matchOption = never; } } matchFlag(s) { const result = super.matchFlag(s); // The flag must be an allowed one. if (result.isSomeAnd((value) => this.allowedFlag(value))) return result; // If it did not match a flag, return null. return result_1.Option.none; } matchOption(s) { const result = super.matchOption(s); if (result.isSomeAnd((option) => this.allowedOption(option[0]))) return result; return result_1.Option.none; } allowedFlag(s) { return this.flags.includes(s); } allowedOption(s) { return this.options.includes(s); } } exports.FlagUnorderedStrategy = FlagUnorderedStrategy; //# sourceMappingURL=flag-unordered-strategy.js.map