UNPKG

cosmic-interchain-cli

Version:

A command-line utility for Cosmic Wire's interchain messaging protocol

37 lines 1.45 kB
import { confirm, input } from '@inquirer/prompts'; import { logGray } from '../logger.js'; import { indentYamlOrJson } from './files.js'; export async function detectAndConfirmOrPrompt(detect, prompt, label, source) { let detectedValue; try { detectedValue = await detect(); if (detectedValue) { const confirmed = await confirm({ message: `Detected ${label} as ${detectedValue}${source ? ` from ${source}` : ''}, is this correct?`, }); if (confirmed) { return detectedValue; } } // eslint-disable-next-line no-empty } catch (e) { } return input({ message: `${prompt} ${label}:`, default: detectedValue }); } const INFO_COMMAND = 'i'; const DOCS_NOTICE = 'For more information, please visit https://docs.hyperlane.xyz.'; export async function inputWithInfo({ message, info = 'No additional information available.', defaultAnswer, }) { let answer = ''; do { answer = await input({ message: message.concat(` [enter '${INFO_COMMAND}' for more info]`), default: defaultAnswer, }); answer = answer.trim().toLowerCase(); const indentedInfo = indentYamlOrJson(`${info}\n${DOCS_NOTICE}\n`, 4); if (answer === INFO_COMMAND) logGray(indentedInfo); } while (answer === INFO_COMMAND); return answer; } //# sourceMappingURL=input.js.map