diff --git a/cmd/gossamer/config.go b/cmd/gossamer/config.go index 8827851f3f..eaaa8dc0bd 100644 --- a/cmd/gossamer/config.go +++ b/cmd/gossamer/config.go @@ -43,22 +43,20 @@ var ( // loadConfigFile loads a default config file if --chain is specified, a specific // config if --config is specified, or the default gossamer config otherwise. func loadConfigFile(ctx *cli.Context, cfg *ctoml.Config) (err error) { - // check --config flag and load toml configuration from config.toml - if cfgPath := ctx.GlobalString(ConfigFlag.Name); cfgPath != "" { - logger.Info("loading toml configuration from " + cfgPath + "...") - if cfg == nil { - cfg = &ctoml.Config{} // if configuration not set, create empty configuration - } else { - logger.Warn( - "overwriting default configuration with id " + cfg.Global.ID + - " with toml configuration values from " + cfgPath) - } - err = loadConfig(cfg, cfgPath) // load toml values into configuration - } else { - err = loadConfig(cfg, defaultGssmrConfigPath) + cfgPath := ctx.GlobalString(ConfigFlag.Name) + if cfgPath == "" { + return loadConfig(cfg, defaultGssmrConfigPath) } - return err + logger.Info("loading toml configuration from " + cfgPath + "...") + if cfg == nil { + cfg = new(ctoml.Config) + } else { + logger.Warn( + "overwriting default configuration with id " + cfg.Global.ID + + " with toml configuration values from " + cfgPath) + } + return loadConfig(cfg, cfgPath) } func setupConfigFromChain(ctx *cli.Context) (*ctoml.Config, *dot.Config, error) { @@ -215,15 +213,14 @@ func createImportStateConfig(ctx *cli.Context) (*dot.Config, error) { } func createBuildSpecConfig(ctx *cli.Context) (*dot.Config, error) { - var tomlCfg *ctoml.Config - cfg := &dot.Config{} + tomlCfg := new(ctoml.Config) err := loadConfigFile(ctx, tomlCfg) if err != nil { logger.Errorf("failed to load toml configuration: %s", err) return nil, err } - // set global configuration values + cfg := new(dot.Config) if err := setDotGlobalConfig(ctx, tomlCfg, &cfg.Global); err != nil { logger.Errorf("failed to set global node configuration: %s", err) return nil, err diff --git a/cmd/gossamer/main.go b/cmd/gossamer/main.go index 087666c72d..87ece94ab7 100644 --- a/cmd/gossamer/main.go +++ b/cmd/gossamer/main.go @@ -80,9 +80,9 @@ var ( Description: "The build-spec command outputs current genesis JSON data.\n" + "\tUsage: gossamer build-spec\n" + "\tTo generate raw genesis file from default: " + - "gossamer build-spec --raw > genesis.json" + + "gossamer build-spec --raw --output genesis.json" + "\tTo generate raw genesis file from specific genesis file: " + - "gossamer build-spec --raw --genesis genesis-spec.json > genesis.json", + "gossamer build-spec --raw --genesis genesis-spec.json --output genesis.json", } // importRuntime generates a genesis file given a .wasm runtime binary. @@ -397,11 +397,12 @@ func buildSpecAction(ctx *cli.Context) error { } if outputPath := ctx.String(OutputSpecFlag.Name); outputPath != "" { - if err = dot.WriteGenesisSpecFile(res, outputPath); err != nil { - return err + err = dot.WriteGenesisSpecFile(res, outputPath) + if err != nil { + return fmt.Errorf("cannot write genesis spec file: %w", err) } } else { - fmt.Printf("%s", res) + fmt.Printf("%s\n", res) } return nil diff --git a/cmd/gossamer/toml_config.go b/cmd/gossamer/toml_config.go index 246966e5f9..e683a80640 100644 --- a/cmd/gossamer/toml_config.go +++ b/cmd/gossamer/toml_config.go @@ -46,7 +46,7 @@ func loadConfig(cfg *ctoml.Config, fp string) error { }, } - if err = tomlSettings.NewDecoder(file).Decode(&cfg); err != nil { + if err = tomlSettings.NewDecoder(file).Decode(cfg); err != nil { logger.Errorf("failed to decode configuration: %s", err) return err }