/*! * @imqueue/cli library: resolve * * I'm Queue Software Project * Copyright (C) 2026 imqueue.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * If you want to use this code in a closed source (commercial) project, you can * purchase a proprietary commercial license. Please contact us at * to get commercial licensing options. */ import type { IMQCLIConfig } from './config.js'; /** * Sources an option value can come from, in precedence order: * cli flags -> per-service config -> global config -> prompt -> default. */ export interface ResolveContext { /** parsed cli flags (e.g. yargs argv) */ flags?: Record; /** per-service config (.imqrc.json), wins over global */ service?: IMQCLIConfig; /** global config (~/.imq/config.json) */ global?: IMQCLIConfig; /** whether interactive prompting is allowed (TTY) */ interactive?: boolean; } /** * Declarative description of how to resolve a single option. */ export interface OptionSpec { /** human name, used in error messages */ name: string; /** flag key(s) to read from ctx.flags */ flag?: string | string[]; /** dot-path to read from service and global config */ path?: string; /** derive a value from legacy keys in the global config */ fromLegacy?: (global: IMQCLIConfig) => T | undefined; /** interactive fallback, only used when ctx.interactive is true */ prompt?: () => Promise; /** default value used when nothing else yields a value */ default?: T; /** when true, a missing final value throws instead of returning undefined */ required?: boolean; /** optional validation applied to a non-undefined resolved value */ validate?: (value: T) => boolean; } /** * Resolves a single option value applying the precedence: * flag -> per-service config -> global config (structured then legacy) -> * prompt (interactive only) -> default. * * @param {OptionSpec} spec - option description * @param {ResolveContext} ctx - available sources * @return {Promise} */ export declare function resolveOption(spec: OptionSpec, ctx: ResolveContext): Promise;