Skip to content

Commit

Permalink
Spec config must exist
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarvardt committed Apr 2, 2020
1 parent a6cda4c commit fc9a5e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
22 changes: 5 additions & 17 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package config

import (
"os"

wErrors "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
Expand Down Expand Up @@ -77,23 +75,13 @@ func (t Tables) FindByName(name string) *Table {

// LoadSpecFromFile loads klepto spec from file
func LoadSpecFromFile(configPath string) (*Spec, error) {
if configPath != "" {
// Use config file from the flag.
log.Debugf("Reading config from %s ...", configPath)
viper.SetConfigFile(configPath)
} else {
log.Debugf("Reading config from %s ...", DefaultConfigFileName)

cwd, err := os.Getwd()
if err != nil {
return nil, wErrors.Wrap(err, "can't find current working directory")
}

viper.SetConfigName(".klepto")
viper.AddConfigPath(cwd)
viper.AddConfigPath(".")
if configPath == "" {
return nil, wErrors.New("config file path can not be empty")
}

log.Debugf("Reading config from %s ...", configPath)
viper.SetConfigFile(configPath)

err := viper.ReadInConfig()
if err != nil {
return nil, wErrors.Wrap(err, "could not read configurations")
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
)

func TestLoadSpecFromFile(t *testing.T) {
_, err := LoadSpecFromFile("")
require.Error(t, err)

cwd, err := os.Getwd()
require.NoError(t, err)

Expand Down

0 comments on commit fc9a5e4

Please sign in to comment.