UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

40 lines (39 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseContext = void 0; /** * Base class for CommandContext implementations. * Handles caching, the `get()` method, and `promptDirect` delegation. * Subclasses only implement the adapter-specific resolution logic. */ class BaseContext { constructor(command) { this.command = command; this.cache = new Map(); } get(name) { if (!this.cache.has(name)) { const spec = this.command.inputs[name]; if (!spec) { return Promise.reject(new Error(`Input "${name}" is not declared in command "${this.command.name}"`)); } // For optional inputs (required: false), catch MissingInputError // and return undefined instead of prompting if (spec.required === false) { this.cache.set(name, this.resolveInput(name, spec).catch(err => { if ((err === null || err === void 0 ? void 0 : err.name) === "MissingInputError") return undefined; throw err; })); } else { this.cache.set(name, this.resolveInput(name, spec)); } } return this.cache.get(name); } async promptDirect(spec) { return this.resolveInput(spec.name, spec); } } exports.BaseContext = BaseContext;