-
Notifications
You must be signed in to change notification settings - Fork 182
/
parse.go
42 lines (33 loc) · 942 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
package cli
import (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/spf13/viper"
govutils "github.com/okex/exchain/libs/cosmos-sdk/x/gov/client/utils"
)
func parseSubmitProposalFlags() (*proposal, error) {
proposal := &proposal{}
proposalFile := viper.GetString(FlagProposal)
if proposalFile == "" {
proposal.Title = viper.GetString(FlagTitle)
proposal.Description = viper.GetString(FlagDescription)
proposal.Type = govutils.NormalizeProposalType(viper.GetString(flagProposalType))
proposal.Deposit = viper.GetString(FlagDeposit)
return proposal, nil
}
for _, flag := range ProposalFlags {
if viper.GetString(flag) != "" {
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
}