-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
parse.go
44 lines (34 loc) · 988 Bytes
/
parse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cli
import (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/spf13/pflag"
govutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
)
func parseSubmitProposalFlags(fs *pflag.FlagSet) (*proposal, error) {
proposal := &proposal{}
proposalFile, _ := fs.GetString(FlagProposal)
if proposalFile == "" {
proposalType, _ := fs.GetString(FlagProposalType)
proposal.Title, _ = fs.GetString(FlagTitle)
proposal.Description, _ = fs.GetString(FlagDescription)
proposal.Type = govutils.NormalizeProposalType(proposalType)
proposal.Deposit, _ = fs.GetString(FlagDeposit)
return proposal, nil
}
for _, flag := range ProposalFlags {
if v, _ := fs.GetString(flag); v != "" {
return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag)
}
}
contents, err := ioutil.ReadFile(proposalFile)
if err != nil {
return nil, err
}
err = json.Unmarshal(contents, proposal)
if err != nil {
return nil, err
}
return proposal, nil
}