UNPKG

@sfdx-falcon/prompt

Version:

Provides a standardized means of user interaction via the console. Part of the SFDX-Falcon Library.

84 lines (83 loc) 3.62 kB
import { Builder } from '@sfdx-falcon/builder'; import { AnswersDisplay } from '@sfdx-falcon/types'; import { ConfirmationAnswers } from '@sfdx-falcon/types'; import { JsonMap } from '@sfdx-falcon/types'; import { Questions } from '@sfdx-falcon/types'; import { QuestionsBuilder } from '@sfdx-falcon/types'; /** * Interface. Represents the options that can be set by the SfdxFalconPrompt constructor. */ export interface PromptOptions<T extends JsonMap> { questions: Questions | QuestionsBuilder | Builder; questionsArgs?: unknown[]; defaultAnswers: T; confirmation?: Questions | QuestionsBuilder | Builder; confirmationArgs?: unknown[]; invertConfirmation?: boolean; display?: AnswersDisplay<T>; context?: object; data?: object; } /** * @class SfdxFalconPrompt * @summary Collection of one or more Inquirer Questions that can be used to gather user input. * @description Allows easy creation of Inquirer prompts that have a "confirmation" question that * can be used to restart collection of the information. * @public */ export declare class SfdxFalconPrompt<T extends JsonMap> { readonly defaultAnswers: T; userAnswers: T; confirmationAnswers: ConfirmationAnswers; private readonly _questions; private readonly _confirmation; private readonly _questionsArgs; private readonly _confirmationArgs; private readonly _display; private readonly _invertConfirmation; /** Returns the set of Inquirer `Questions` that will be displayed during the 'confirmation' phase of the prompt. */ readonly confirmation: Questions; /** Returns a union of Default and User Answers, representing the "final" set of answers to this prompt. */ readonly finalAnswers: T; /** Returns the set of Inquirer `Questions` that will be displayed as the main part of this prompt. */ readonly questions: Questions; /** * @constructs SfdxFalconPrompt * @param {PromptOptions<T>} opts Required. Options that define the * questions, default answers, confirmation questions, and * Prompt Engine that should be used by this SfdxFalconPrompt * object. * @description Constructs an SfdxFalconPrompt object. * @public */ constructor(opts: PromptOptions<T>); /** * @method prompt * @returns {Promise<T>} Returns the answers provided by the user. * @description Uses an Inquirer prompt() function to show the questions defined * in this SfdxFalconPrompt to the user and returns their input. * @public @async */ prompt(): Promise<T>; /** * @method confirmRestart * @returns {Promise<boolean>} Returns true if the user wants to restart, * false if otherwise. * @description If this.confirmation contains Questions, prompts the user with * those questions and then decides to continue or restart based * on the answers. * @private @async */ private confirmRestart; /** * @method displayAnswers * @returns {Promise<void>} * @description Uses the Display function (if present) to display the User * Answers from the prompt to the user. If the Display function * returns void, it means that it rendered output to the user. * If it returns an Array, it means that we need to manually * render the returned data in a FalconTable. * @private @async */ private displayAnswers; }