json testing, addressed init option PR comments

This commit is contained in:
rigelrozanski
2017-09-06 01:19:20 -04:00
parent 748a1e97e4
commit 4ac089f084
4 changed files with 27 additions and 12 deletions
+6 -5
View File
@@ -31,7 +31,7 @@ var (
func init() {
InitCmd.Flags().String(FlagChainID, "test_chain_id", "Chain ID")
InitCmd.Flags().StringSlice(FlagOption, []string{}, "Genesis option in the format <app>/<option>/<value>")
InitCmd.Flags().StringSliceP(FlagOption, "p", []string{}, "Genesis option in the format <app>/<option>/<value>")
}
// returns 1 iff it set a file, otherwise 0 (so we can add them)
@@ -67,12 +67,13 @@ func initCmd(cmd *cobra.Command, args []string) error {
return errors.New("Address must be 20-bytes in hex")
}
var options []string
var optionsStr string
sep := ",\n "
optionsRaw := viper.GetStringSlice(FlagOption)
if len(optionsRaw) > 0 {
optionsStr = sep
var options []string
sep := ",\n "
for i := 0; i < len(optionsRaw); i++ {
s := strings.SplitN(optionsRaw[i], "/", 3)
if len(s) != 3 {
@@ -87,8 +88,8 @@ func initCmd(cmd *cobra.Command, args []string) error {
option := `"` + s[0] + `/` + s[1] + `", ` + s[2]
options = append(options, option)
}
optionsStr = sep + strings.Join(options[:], sep)
}
optionsStr += strings.Join(options[:], sep)
genesis := GetGenesisJSON(viper.GetString(FlagChainID), userAddr, optionsStr)
return CreateGenesisValidatorFiles(cfg, genesis, cmd.Root().Name())
+1
View File
@@ -35,6 +35,7 @@ func preRunSetup(cmd *cobra.Command, args []string) (err error) {
return nil
}
// SetUpRoot - initialize the root command
func SetUpRoot(cmd *cobra.Command) {
cmd.PersistentPreRunE = preRunSetup
cmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level")