Skip to content

Commit 1776574

Browse files
committed
Deprecate verbose dir value in config
1 parent 585dd8c commit 1776574

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎config/config.go‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ var (
3737
// where to put problems that get downloaded.
3838
type Config struct {
3939
APIKey string `json:"apiKey"`
40-
Dir string `json:"exercismDirectory"`
40+
Dir string `json:"dir"`
4141
Hostname string `json:"hostname"`
4242
ProblemsHost string `json:"problemsHost"`
4343
home string // cache user's home directory
4444
file string // full path to config file
45+
46+
// deprecated
47+
ExercismDirectory string `json:"exercismDirectory,omitempty"`
4548
}
4649

4750
// Home returns the user's canonical home directory.
@@ -133,6 +136,7 @@ func (c *Config) File() string {
133136
// Write() saves the config as JSON.
134137
func (c *Config) Write() error {
135138
renameLegacy()
139+
c.ExercismDirectory = ""
136140

137141
// truncates existing file if it exists
138142
f, err := os.Create(c.file)
@@ -162,6 +166,12 @@ func (c *Config) configure() (*Config, error) {
162166
}
163167
c.file = fmt.Sprintf("%s/%s", dir, File)
164168

169+
// use legacy value, if it exists
170+
if c.ExercismDirectory != "" {
171+
c.Dir = c.ExercismDirectory
172+
}
173+
174+
// fall back to default value
165175
if c.Dir == "" {
166176
c.Dir = fmt.Sprintf("%s/%s", dir, DirExercises)
167177
}

‎config/config_test.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,17 @@ func TestReadCustomConfig(t *testing.T) {
123123
assert.Equal(t, "http://example.org", c.Hostname)
124124
assert.Equal(t, "http://x.example.org", c.ProblemsHost)
125125
}
126+
127+
func TestReadLegacyConfig(t *testing.T) {
128+
dir, err := filepath.Abs("../fixtures/home/")
129+
assert.NoError(t, err)
130+
131+
c := &Config{home: dir}
132+
file := fmt.Sprintf("%s/legacy.json", dir)
133+
err = c.Read(file)
134+
assert.NoError(t, err)
135+
assert.Equal(t, "prq567", c.APIKey)
136+
assert.Equal(t, "/tmp/stuff", c.Dir)
137+
assert.Equal(t, "http://api.example.com", c.Hostname)
138+
assert.Equal(t, "http://problems.example.com", c.ProblemsHost)
139+
}

‎fixtures/home/.exercism.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"apiKey":"abc123","exercismDirectory":"/path/to/exercism","hostname":"http://example.com","problemsHost":"http://x.example.com"}
1+
{"apiKey":"abc123","dir":"/path/to/exercism","hostname":"http://example.com","problemsHost":"http://x.example.com"}

‎fixtures/home/custom.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"apiKey":"xyz000","exercismDirectory":"/tmp/exercism","hostname":"http://example.org","problemsHost":"http://x.example.org"}
1+
{"apiKey":"xyz000","dir":"/tmp/exercism","hostname":"http://example.org","problemsHost":"http://x.example.org"}

‎fixtures/home/legacy.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"apiKey":"prq567","exercismDirectory":"/tmp/stuff","hostname":"http://api.example.com","problemsHost":"http://problems.example.com"}

0 commit comments

Comments
 (0)