Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ func (c *Config) resolvePath(argPath string) (string, error) {
if err != nil {
return "", err
}
return strings.Replace(path, "~", h, 1), nil
path = strings.Replace(path, "~", h, 1)

fi, _ := os.Stat(path)
if fi != nil && fi.IsDir() {
path = filepath.Join(path, File)
}

return path, nil
}

func (c *Config) setDefaults() error {
Expand Down
19 changes: 19 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ func TestLoad(t *testing.T) {
}
}

func TestReadDirectory(t *testing.T) {
// if the provided path is a directory, append the default filename
tmpDir, err := ioutil.TempDir("", "")
assert.NoError(t, err)

myConfig, err := New(tmpDir)
assert.NoError(t, err)

expected := filepath.Join(tmpDir, File)
actual := myConfig.File
assert.Equal(t, expected, actual)

// if it can't determine if the provided path is a directory, don't modify
// the path
myConfig, err = New("badpath")
assert.NoError(t, err)
assert.Equal(t, "badpath", myConfig.File)
}

func TestReadingWritingConfig(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "")
filename := fmt.Sprintf("%s/%s", tmpDir, File)
Expand Down
2 changes: 1 addition & 1 deletion exercism/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {
cli.StringFlag{
Name: "config, c",
Usage: "path to config file",
EnvVar: "EXERCISM_CONFIG_FILE",
EnvVar: "XDG_CONFIG_HOME,EXERCISM_CONFIG_FILE",
},
cli.BoolFlag{
Name: "verbose, v",
Expand Down