78 lines
3.0 KiB
JavaScript
Executable File
78 lines
3.0 KiB
JavaScript
Executable File
"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.positional = void 0;
|
|
const Result = __importStar(require("./Result"));
|
|
const types_1 = require("./types");
|
|
function fullPositional(config) {
|
|
var _a, _b, _c;
|
|
const displayName = (_b = (_a = config.displayName) !== null && _a !== void 0 ? _a : config.type.displayName) !== null && _b !== void 0 ? _b : 'arg';
|
|
return {
|
|
description: (_c = config.description) !== null && _c !== void 0 ? _c : config.type.description,
|
|
helpTopics() {
|
|
var _a, _b;
|
|
return [
|
|
{
|
|
category: 'arguments',
|
|
usage: `<${displayName}>`,
|
|
description: (_b = (_a = config.description) !== null && _a !== void 0 ? _a : config.type.description) !== null && _b !== void 0 ? _b : 'self explanatory',
|
|
defaults: [],
|
|
},
|
|
];
|
|
},
|
|
register(_opts) { },
|
|
async parse({ nodes, visitedNodes, }) {
|
|
const positionals = nodes.filter((node) => node.type === 'positionalArgument' && !visitedNodes.has(node));
|
|
const positional = positionals[0];
|
|
if (!positional) {
|
|
return Result.err({
|
|
errors: [
|
|
{
|
|
nodes: [],
|
|
message: `No value provided for ${displayName}`,
|
|
},
|
|
],
|
|
});
|
|
}
|
|
visitedNodes.add(positional);
|
|
const decoded = await Result.safeAsync(config.type.from(positional.raw));
|
|
if (Result.isErr(decoded)) {
|
|
return Result.err({
|
|
errors: [
|
|
{
|
|
nodes: [positional],
|
|
message: decoded.error.message,
|
|
},
|
|
],
|
|
});
|
|
}
|
|
return Result.ok(decoded.value);
|
|
},
|
|
};
|
|
}
|
|
function positional(config) {
|
|
return fullPositional({
|
|
type: types_1.string,
|
|
...config,
|
|
});
|
|
}
|
|
exports.positional = positional;
|
|
//# sourceMappingURL=positional.js.map
|