From 3e9632069419c018c8eeed85d004e59fd3cd3468 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Tue, 14 Nov 2023 15:40:55 -0500 Subject: [PATCH] brining back showPromptsText function --- internal/cli/prompts_custom_text.go | 68 +++++++++++++++-------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/internal/cli/prompts_custom_text.go b/internal/cli/prompts_custom_text.go index eb5a1698e..5c2e70652 100644 --- a/internal/cli/prompts_custom_text.go +++ b/internal/cli/prompts_custom_text.go @@ -85,38 +85,7 @@ func showPromptsTextCmd(cli *cli) *cobra.Command { auth0 ul prompts show -l auth0 ul prompts show signup -l es`, - RunE: func(cmd *cobra.Command, args []string) error { - brandingText := make(map[string]interface{}) - - if len(args) == 0 { - if err := customTextPrompt.Pick(cmd, &inputs.Prompt, customTextPromptOptions); err != nil { - return err - } - } else { - inputs.Prompt = args[0] - } - - if err := ansi.Waiting(func() (err error) { - brandingText, err = cli.api.Prompt.CustomText(cmd.Context(), inputs.Prompt, inputs.Language) - return err - }); err != nil { - return fmt.Errorf( - "unable to fetch custom text for prompt %s and language %s: %w", - inputs.Prompt, - inputs.Language, - err, - ) - } - - brandingTextJSON, err := json.MarshalIndent(brandingText, "", " ") - if err != nil { - return fmt.Errorf("failed to serialize the prompt custom text to JSON: %w", err) - } - - cli.renderer.BrandingTextShow(string(brandingTextJSON), inputs.Prompt, inputs.Language) - - return nil - }, + RunE: showPromptsText(cli, &inputs), } textLanguage.RegisterString(cmd, &inputs.Language, textLanguageDefault) @@ -143,6 +112,41 @@ func updatePromptsTextCmd(cli *cli) *cobra.Command { return cmd } +func showPromptsText(cli *cli, inputs *promptsTextInput) func(cmd *cobra.Command, args []string) error { + return func(cmd *cobra.Command, args []string) error { + + if len(args) == 0 { + if err := customTextPrompt.Pick(cmd, &inputs.Prompt, customTextPromptOptions); err != nil { + return err + } + } else { + inputs.Prompt = args[0] + } + + brandingText := make(map[string]interface{}) + if err := ansi.Waiting(func() (err error) { + brandingText, err = cli.api.Prompt.CustomText(cmd.Context(), inputs.Prompt, inputs.Language) + return err + }); err != nil { + return fmt.Errorf( + "unable to fetch custom text for prompt %s and language %s: %w", + inputs.Prompt, + inputs.Language, + err, + ) + } + + brandingTextJSON, err := json.MarshalIndent(brandingText, "", " ") + if err != nil { + return fmt.Errorf("failed to serialize the prompt custom text to JSON: %w", err) + } + + cli.renderer.BrandingTextShow(string(brandingTextJSON), inputs.Prompt, inputs.Language) + + return nil + } +} + func updateBrandingText(cli *cli, inputs *promptsTextInput) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { if len(args) == 0 {