From 6108d0a9b53888f179760262def787267cf7e524 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Thu, 28 Oct 2021 11:17:23 +0200 Subject: [PATCH] config: expose ability to write config to arbitrary paths (#7174) --- config/toml.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/config/toml.go b/config/toml.go index 94c1907e8..a57e14b9b 100644 --- a/config/toml.go +++ b/config/toml.go @@ -46,15 +46,20 @@ func EnsureRoot(rootDir string) { // WriteConfigFile renders config using the template and writes it to configFilePath. // This function is called by cmd/tendermint/commands/init.go func WriteConfigFile(rootDir string, config *Config) error { + return config.WriteToTemplate(filepath.Join(rootDir, defaultConfigFilePath)) +} + +// WriteToTemplate writes the config to the exact file specified by +// the path, in the default toml template and does not mangle the path +// or filename at all. +func (cfg *Config) WriteToTemplate(path string) error { var buffer bytes.Buffer - if err := configTemplate.Execute(&buffer, config); err != nil { + if err := configTemplate.Execute(&buffer, cfg); err != nil { return err } - configFilePath := filepath.Join(rootDir, defaultConfigFilePath) - - return writeFile(configFilePath, buffer.Bytes(), 0644) + return writeFile(path, buffer.Bytes(), 0644) } func writeDefaultConfigFileIfNone(rootDir string) error {