@ -6,12 +6,35 @@ import {EditorQuestion, ExpandQuestion} from "inquirer";
const RETRY = "Retry"
const ABORT = "Abort"
export type EditYamlInquire = InquireFunction < EditorQuestion , string > & InquireFunction < ExpandQuestion , typeof RETRY | typeof ABORT >
export interface YamlPromptOptions < ObjectT > {
schema : AnySchemaDataFor < ObjectT >
currentValue : ObjectT | undefined
name : string
}
export interface YamlPromptSetOptions < ObjectT > extends YamlPromptOptions < ObjectT > {
currentValue : ObjectT
}
export interface YamlPromptDependencies {
inquire : InquireFunction < EditorQuestion , string > & InquireFunction < ExpandQuestion , typeof RETRY | typeof ABORT >
showError : ShowFunction
}
export type YamlPromptFunction = ( < ObjectT > ( opts : YamlPromptSetOptions < ObjectT > ) = > Promise < ObjectT > ) & ( < ObjectT > ( opts : YamlPromptOptions < ObjectT > ) = > Promise < ObjectT | undefined > )
export function yamlPrompt ( deps : YamlPromptDependencies ) : YamlPromptFunction {
function injectedYamlPrompt < ObjectT > ( opts : YamlPromptSetOptions < ObjectT > ) : Promise < ObjectT >
function injectedYamlPrompt < ObjectT > ( opts : YamlPromptOptions < ObjectT > ) : Promise < ObjectT | undefined >
function injectedYamlPrompt < ObjectT > ( opts : YamlPromptOptions < ObjectT > ) : Promise < ObjectT | undefined > {
return promptForYaml < ObjectT > ( opts , deps )
}
return injectedYamlPrompt
}
// TODO: Inject this one's dependencies (inquire, showError) as well, instead of making callers do it, and give it to said callers.
export async function editYaml < ObjectT extends object > ( { schema , currentValue , name , inquire , showError } : { schema : AnySchemaDataFor < ObjectT > , currentValue : ObjectT , name : string , inquire : EditYamlInquire , showError : ShowFunction } ) : Promise < ObjectT >
export async function editYaml < ObjectT extends object > ( { schema , currentValue , name , inquire , showError } : { schema : AnySchemaDataFor < ObjectT > , currentValue : ObjectT | undefined , name : string , inquire : EditYamlInquire , showError : ShowFunction } ) : Promise < ObjectT | undefined >
export async function editYaml < ObjectT extends object > ( { schema , currentValue , name , inquire , showError } : { schema : AnySchemaDataFor < ObjectT > , currentValue : ObjectT | undefined , name : string , inquire : EditYamlInquire , showError : ShowFunction } ) : Promise < ObjectT | undefined > {
export async function promptForYaml < ObjectT > ( { schema , currentValue , name } : YamlPromptSetOptions < ObjectT > , { inquire , showError } : YamlPromptDependencies ) : Promise < ObjectT >
export async function promptForYaml < ObjectT > ( { schema , currentValue , name } : YamlPromptOptions < ObjectT > , { inquire , showError } : YamlPromptDependencies ) : Promise < ObjectT | undefined >
export async function promptForYaml < ObjectT > ( { schema , currentValue , name } : YamlPromptOptions < ObjectT > , { inquire , showError } : YamlPromptDependencies ) : Promise < ObjectT | undefined > {
const original = dump ( currentValue )
let text = original
while ( true ) {