import * as Result from './Result'; import { string } from './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); }, }; } export function restPositionals(config) { return fullRestPositionals({ type: string, ...config, }); } //# sourceMappingURL=restPositionals.js.map