Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Write Config With No Extension #829

Closed
seemywingz opened this issue Jan 16, 2020 · 3 comments · Fixed by #813
Closed

Cannot Write Config With No Extension #829

seemywingz opened this issue Jan 16, 2020 · 3 comments · Fixed by #813

Comments

@seemywingz
Copy link

seemywingz commented Jan 16, 2020

I realize there are other issues related to configs with no extension, but I didn't see this one

When writing a config with no extension I get this error:
filename: /Users/kjayne/.test/config requires valid extension
It seems to find the config file just fine...
unless I'm missing something

Sample Code main.go

package main

import (
	"fmt"

	"github.com/mitchellh/go-homedir"
	"github.com/spf13/viper"
)

func main() {

	// Find home directory.
	homeDir, err := homedir.Dir()
	if err != nil {
		fmt.Println("Error Getting Home Directory", err)
		return
	}

	configName := "config"
	configDir := homeDir + "/.test"
	configFile := configDir + "/" + configName

	viper.SetConfigType("json")
	viper.AddConfigPath(configDir)
	viper.SetConfigName(configName)

	fmt.Println("config name:", configName)
	fmt.Println("config dir:", configDir)
	fmt.Println("config file:", configFile)

	fmt.Println("read config error:", viper.ReadInConfig())
	fmt.Println("write config error:", viper.WriteConfig())
	fmt.Println("write config error:", viper.WriteConfigAs(configFile))

}

Console Output go run main.go

config name: config
config dir: /Users/kjayne/.test
config file: /Users/kjayne/.test/config
read config error: <nil>
write config error: filename: /Users/kjayne/.test/config requires valid extension
write config error: filename: /Users/kjayne/.test/config requires valid extension
@sagikazarmark sagikazarmark linked a pull request Feb 19, 2020 that will close this issue
@sagikazarmark
Copy link
Collaborator

@seemywingz Can you check if ☝️ solves your issue?

@montanaflynn
Copy link

montanaflynn commented May 19, 2020

I still get the issue on OSX with viper v1.7.0:

config name: config
config dir: /Users/montanaflynn/.test
config file: /Users/montanaflynn/.test/config
read config error: Config File "config" Not Found in "[/Users/montanaflynn/.test]"
write config error: Config File "config" Not Found in "[/Users/montanaflynn/.test]"
write config error: Filename: /Users/montanaflynn/.test/config requires valid extension.

@seemywingz
Copy link
Author

Hey! Sorry for the late response
I can confirm that Add support to save file with no extension #813 does indeed fix this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants