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

Add support to save file with no extension #813

Merged
merged 4 commits into from Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions viper.go
Expand Up @@ -1418,11 +1418,18 @@ func (v *Viper) SafeWriteConfigAs(filename string) error {

func (v *Viper) writeConfig(filename string, force bool) error {
jww.INFO.Println("Attempting to write configuration to file.")
var configType string

ext := filepath.Ext(filename)
if len(ext) <= 1 {
return fmt.Errorf("filename: %s requires valid extension", filename)
if ext != "" {
configType = ext[1:]
} else {
configType = v.configType
}
configType := ext[1:]
if configType == "" {
return fmt.Errorf("config type could not be determined for %s", filename)
}

if !stringInSlice(configType, SupportedExts) {
return UnsupportedConfigError(configType)
}
Expand Down