Skip to content

Commit aa3525d

Browse files
committed
clean up logic in configure
* remove setDir - we had to refetch homeDir because we didn't have access to it in setDir * better communicate possible program flow - 1) the path where we set c.Dir with a default value and 2) the path where we expand tilde are mutually exclusive
1 parent 63a0618 commit aa3525d

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

‎config/config.go‎

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (c *Config) configure() (*Config, error) {
194194
c.XAPI = hostXAPI
195195
}
196196

197-
dir, err := c.homeDir()
197+
homeDir, err := c.homeDir()
198198
if err != nil {
199199
return c, err
200200
}
@@ -204,33 +204,21 @@ func (c *Config) configure() (*Config, error) {
204204
c.Dir = c.ExercismDirectory
205205
}
206206

207-
// fall back to default value
208207
if c.Dir == "" {
209-
c.Dir = filepath.Join(dir, DirExercises)
210-
}
211-
212-
if err := c.setDir(c.Dir); err != nil {
213-
return c, err
208+
// fall back to default value
209+
c.Dir = filepath.Join(homeDir, DirExercises)
210+
} else {
211+
// replace '~' with user's home
212+
c.Dir = strings.Replace(c.Dir, "~/", fmt.Sprintf("%s/", homeDir), 1)
214213
}
215214

216215
if c.File == "" {
217-
c.File = filepath.Join(dir, File)
216+
c.File = filepath.Join(homeDir, File)
218217
}
219218

220219
return c, nil
221220
}
222221

223-
func (c *Config) setDir(dir string) error {
224-
homeDir, err := c.homeDir()
225-
if err != nil {
226-
return err
227-
}
228-
229-
c.Dir = strings.Replace(dir, "~/", fmt.Sprintf("%s/", homeDir), 1)
230-
231-
return nil
232-
}
233-
234222
// FilePath returns the path to the config file.
235223
func FilePath(file string) (string, error) {
236224
if file != "" {

0 commit comments

Comments
 (0)