"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.restPositionals = void 0; const Result = __importStar(require("./Result")); const types_1 = require("./types"); /** * Read all the positionals and decode them using the type provided. * Works best when it is the last item on the `command` construct, to be * used like the `...rest` operator in JS and TypeScript. */ function fullRestPositionals(config) { return { helpTopics() { var _a, _b, _c, _d; const displayName = (_b = (_a = config.displayName) !== null && _a !== void 0 ? _a : config.type.displayName) !== null && _b !== void 0 ? _b : 'arg'; return [ { usage: `[...${displayName}]`, category: 'arguments', defaults: [], description: (_d = (_c = config.description) !== null && _c !== void 0 ? _c : config.type.description) !== null && _d !== void 0 ? _d : '', }, ]; }, register(_opts) { }, async parse({ nodes, visitedNodes, }) { const positionals = nodes.filter((node) => node.type === 'positionalArgument' && !visitedNodes.has(node)); const results = []; let errors = []; for (const positional of positionals) { visitedNodes.add(positional); const decoded = await Result.safeAsync(config.type.from(positional.raw)); if (Result.isOk(decoded)) { results.push(decoded.value); } else { errors.push({ nodes: [positional], message: decoded.error.message, }); } } if (errors.length > 0) { return Result.err({ errors, }); } return Result.ok(results); }, }; } function restPositionals(config) { return fullRestPositionals({ type: types_1.string, ...config, }); } exports.restPositionals = restPositionals; //# sourceMappingURL=restPositionals.js.map