Merge PR #3316: Fix regression in gaiacli config file handling
* --chain-id must be a persistent flag to be successfully read from config * Prevent panic when not enough arguments * Add docs on gaiacli config * Small tweak
This commit is contained in:
committed by
Christopher Goes
parent
7fbc2822e8
commit
20bcacfaf4
@@ -98,6 +98,7 @@ func InitFixtures(t *testing.T) (f *Fixtures) {
|
||||
|
||||
// NOTE: GDInit sets the ChainID
|
||||
f.GDInit(keyFoo)
|
||||
f.CLIConfig("chain-id", f.ChainID)
|
||||
|
||||
// Start an account with tokens
|
||||
f.AddGenesisAccount(f.KeyAddress(keyFoo), startCoins)
|
||||
@@ -117,7 +118,7 @@ func (f *Fixtures) Cleanup(dirs ...string) {
|
||||
|
||||
// Flags returns the flags necessary for making most CLI calls
|
||||
func (f *Fixtures) Flags() string {
|
||||
return fmt.Sprintf("--home=%s --node=%s --chain-id=%s", f.GCLIHome, f.RPCAddr, f.ChainID)
|
||||
return fmt.Sprintf("--home=%s --node=%s", f.GCLIHome, f.RPCAddr)
|
||||
}
|
||||
|
||||
//___________________________________________________________________________________
|
||||
|
||||
@@ -75,6 +75,12 @@ func main() {
|
||||
Short: "Command line interface for interacting with gaiad",
|
||||
}
|
||||
|
||||
// Add --chain-id to persistent flags and mark it required
|
||||
rootCmd.PersistentFlags().String(client.FlagChainID, "", "Chain ID of tendermint node")
|
||||
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
|
||||
return initConfig(rootCmd)
|
||||
}
|
||||
|
||||
// Construct Root Command
|
||||
rootCmd.AddCommand(
|
||||
rpc.StatusCommand(),
|
||||
@@ -91,12 +97,8 @@ func main() {
|
||||
|
||||
// Add flags and prefix all env exposed with GA
|
||||
executor := cli.PrepareMainCmd(rootCmd, "GA", app.DefaultCLIHome)
|
||||
err := initConfig(rootCmd)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = executor.Execute()
|
||||
err := executor.Execute()
|
||||
if err != nil {
|
||||
fmt.Printf("Failed executing CLI command: %s, exiting...\n", err)
|
||||
os.Exit(1)
|
||||
@@ -186,7 +188,9 @@ func initConfig(cmd *cobra.Command) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := viper.BindPFlag(client.FlagChainID, cmd.PersistentFlags().Lookup(client.FlagChainID)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := viper.BindPFlag(cli.EncodingFlag, cmd.PersistentFlags().Lookup(cli.EncodingFlag)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user