Skip to content

Commit

Permalink
chore(x/gov): improve PromptMetadata readability (#17859)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Sep 25, 2023
1 parent bb35cf1 commit 2a29c7e
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions x/gov/client/cli/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2a29c7e

Please sign in to comment.