Skip to content

Commit

Permalink
brining back showPromptsText function
Browse files Browse the repository at this point in the history
  • Loading branch information
willvedd committed Nov 14, 2023
1 parent eb8d2fa commit 3e96320
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions internal/cli/prompts_custom_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,38 +85,7 @@ func showPromptsTextCmd(cli *cli) *cobra.Command {
auth0 ul prompts show <prompt> -l <language>
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)
Expand All @@ -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 {
Expand Down

0 comments on commit 3e96320

Please sign in to comment.