-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: Add support for []string
and []int
in draft-proposal
prompt.
#14483
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5235717
feat: Add support for `[]string` and `[]int` in `draft-proposal` prompt.
julienrbrt f52d7b5
add changelog
julienrbrt 70f88bf
update group doc
julienrbrt 9624e03
updates
julienrbrt 20cb328
updates
julienrbrt 4fb01a3
updates
julienrbrt 70a98f8
updates
julienrbrt 03fab11
Merge branch 'main' into julien/draft-proposal-metadata
julienrbrt 17bdf4d
Merge branch 'main' into julien/draft-proposal-metadata
julienrbrt ee456e9
Merge branch 'main' into julien/draft-proposal-metadata
julienrbrt 13678e8
Merge branch 'main' into julien/draft-proposal-metadata
julienrbrt 07e41f7
address comments
julienrbrt e611976
Merge branch 'main' into julien/draft-proposal-metadata
julienrbrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -63,9 +63,11 @@ func Prompt[T any](data T, namePrefix string) (T, error) { | |||||||
} | ||||||||
|
||||||||
for i := 0; i < v.NumField(); i++ { | ||||||||
if v.Field(i).Kind() == reflect.Struct || v.Field(i).Kind() == reflect.Slice { | ||||||||
// if the field is a struct skip | ||||||||
// in a future we can add a recursive call to Prompt | ||||||||
// if the field is a struct skip or not slice of string or int then skip | ||||||||
// TODO in the future we can add a recursive call to Prompt | ||||||||
if v.Field(i).Kind() == reflect.Struct || | ||||||||
(v.Field(i).Kind() == reflect.Slice && | ||||||||
(v.Field(i).Type().Elem().Kind() != reflect.String && v.Field(i).Type().Elem().Kind() != reflect.Int)) { | ||||||||
julienrbrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
continue | ||||||||
} | ||||||||
|
||||||||
|
@@ -117,9 +119,20 @@ func Prompt[T any](data T, namePrefix string) (T, error) { | |||||||
// of which on 64-bit machines, which are most common, | ||||||||
// int==int64 | ||||||||
v.Field(i).SetInt(resultInt) | ||||||||
case reflect.Slice: | ||||||||
switch v.Field(i).Type().Elem().Kind() { | ||||||||
case reflect.String: | ||||||||
v.Field(i).Set(reflect.ValueOf([]string{result})) | ||||||||
case reflect.Int: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
resultInt, err := strconv.ParseInt(result, 10, 0) | ||||||||
if err != nil { | ||||||||
return data, fmt.Errorf("invalid value for int: %w", err) | ||||||||
} | ||||||||
|
||||||||
v.Field(i).Set(reflect.ValueOf([]int{int(resultInt)})) | ||||||||
} | ||||||||
default: | ||||||||
// skip other types | ||||||||
// possibly in the future we can add more types (like slices) | ||||||||
// skip any other types | ||||||||
continue | ||||||||
} | ||||||||
} | ||||||||
|
@@ -172,6 +185,7 @@ func (p *proposalType) Prompt(cdc codec.Codec) (*proposal, types.ProposalMetadat | |||||||
return nil, metadata, fmt.Errorf("failed to marshal proposal message: %w", err) | ||||||||
} | ||||||||
proposal.Messages = append(proposal.Messages, message) | ||||||||
|
||||||||
return proposal, metadata, nil | ||||||||
} | ||||||||
|
||||||||
|
@@ -256,7 +270,7 @@ func NewCmdDraftProposal() *cobra.Command { | |||||||
return err | ||||||||
} | ||||||||
|
||||||||
fmt.Printf("Your draft proposal has successfully been generated.\nProposals should contain off-chain metadata, please upload the metadata JSON to IPFS.\nThen, replace the generated metadata field with the IPFS CID.\n") | ||||||||
fmt.Printf("The draft proposal has successfully been generated.\nProposals should contain off-chain metadata, please upload the metadata JSON to IPFS.\nThen, replace the generated metadata field with the IPFS CID.\n") | ||||||||
|
||||||||
return nil | ||||||||
}, | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment made me re-check everything: #14482 (comment) and this was bumped with the params changes already.