2019-02-08 13:45:41 -08:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
|
2020-07-06 03:12:00 -07:00
|
|
|
"github.com/spf13/pflag"
|
2019-02-08 13:45:41 -08:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
govutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
2019-02-08 13:45:41 -08:00
|
|
|
)
|
|
|
|
|
2020-07-06 03:12:00 -07:00
|
|
|
func parseSubmitProposalFlags(fs *pflag.FlagSet) (*proposal, error) {
|
2019-02-08 13:45:41 -08:00
|
|
|
proposal := &proposal{}
|
2020-07-06 03:12:00 -07:00
|
|
|
proposalFile, _ := fs.GetString(FlagProposal)
|
2019-02-08 13:45:41 -08:00
|
|
|
|
|
|
|
if proposalFile == "" {
|
2020-07-21 06:54:07 -07:00
|
|
|
proposalType, _ := fs.GetString(FlagProposalType)
|
2020-07-06 03:12:00 -07:00
|
|
|
|
|
|
|
proposal.Title, _ = fs.GetString(FlagTitle)
|
|
|
|
proposal.Description, _ = fs.GetString(FlagDescription)
|
|
|
|
proposal.Type = govutils.NormalizeProposalType(proposalType)
|
|
|
|
proposal.Deposit, _ = fs.GetString(FlagDeposit)
|
2019-02-08 13:45:41 -08:00
|
|
|
return proposal, nil
|
|
|
|
}
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
for _, flag := range ProposalFlags {
|
2020-07-06 03:12:00 -07:00
|
|
|
if v, _ := fs.GetString(flag); v != "" {
|
2019-02-08 13:45:41 -08:00
|
|
|
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
|
|
|
|
}
|