From 2a29c7ea80f05c9bbbe7ef499702fc5654d8b045 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 25 Sep 2023 11:50:17 +0200 Subject: [PATCH] chore(x/gov): improve `PromptMetadata` readability (#17859) --- x/gov/client/cli/prompt.go | 47 ++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/x/gov/client/cli/prompt.go b/x/gov/client/cli/prompt.go index 2267ddc5052f..1722c53e2eab 100644 --- a/x/gov/client/cli/prompt.go +++ b/x/gov/client/cli/prompt.go @@ -199,40 +199,37 @@ func getProposalSuggestions() []string { // PromptMetadata prompts for proposal metadata or only title and summary if skip is true func PromptMetadata(skip bool) (types.ProposalMetadata, error) { - var ( - metadata types.ProposalMetadata - err error - ) - if !skip { - metadata, err = Prompt(types.ProposalMetadata{}, "proposal") + metadata, err := Prompt(types.ProposalMetadata{}, "proposal") if err != nil { return metadata, fmt.Errorf("failed to set proposal metadata: %w", err) } - } else { - // prompt for title and summary - titlePrompt := promptui.Prompt{ - Label: "Enter proposal title", - Validate: client.ValidatePromptNotEmpty, - } - metadata.Title, err = titlePrompt.Run() - if err != nil { - return metadata, fmt.Errorf("failed to set proposal title: %w", err) - } + return metadata, nil + } - summaryPrompt := promptui.Prompt{ - Label: "Enter proposal summary", - Validate: client.ValidatePromptNotEmpty, - } + // prompt for title and summary + titlePrompt := promptui.Prompt{ + Label: "Enter proposal title", + Validate: client.ValidatePromptNotEmpty, + } - metadata.Summary, err = summaryPrompt.Run() - if err != nil { - return metadata, fmt.Errorf("failed to set proposal summary: %w", err) - } + title, err := titlePrompt.Run() + if err != nil { + return types.ProposalMetadata{}, fmt.Errorf("failed to set proposal title: %w", err) + } + + summaryPrompt := promptui.Prompt{ + Label: "Enter proposal summary", + Validate: client.ValidatePromptNotEmpty, + } + + summary, err := summaryPrompt.Run() + if err != nil { + return types.ProposalMetadata{}, fmt.Errorf("failed to set proposal summary: %w", err) } - return metadata, nil + return types.ProposalMetadata{Title: title, Summary: summary}, nil } // NewCmdDraftProposal let a user generate a draft proposal.