Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(x/gov): improve PromptMetadata readability #17859

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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