Skip to content

Commit 0ff0d22

Browse files
committed
Merge pull request #421 from Joshua-Anderson/config-pull
feat(config): add pipe suport to config:pull
2 parents 80df531 + 21fbd22 commit 0ff0d22

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

client/cmd/config.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,36 @@ func ConfigUnset(appID string, configVars []string) error {
151151

152152
// ConfigPull pulls an app's config to a file.
153153
func ConfigPull(appID string, interactive bool, overwrite bool) error {
154-
filename := ".env"
154+
c, appID, err := load(appID)
155155

156-
if !overwrite {
157-
if _, err := os.Stat(filename); err == nil {
158-
return fmt.Errorf("%s already exists, pass -o to overwrite", filename)
159-
}
156+
if err != nil {
157+
return err
160158
}
161159

162-
c, appID, err := load(appID)
160+
configVars, err := config.List(c, appID)
163161

164162
if err != nil {
165163
return err
166164
}
167165

168-
configVars, err := config.List(c, appID)
166+
stat, err := os.Stdout.Stat()
167+
168+
if err != nil {
169+
return err
170+
}
171+
172+
if (stat.Mode() & os.ModeCharDevice) == 0 {
173+
fmt.Print(formatConfig(configVars.Values))
174+
return nil
175+
}
176+
177+
filename := ".env"
178+
179+
if !overwrite {
180+
if _, err := os.Stat(filename); err == nil {
181+
return fmt.Errorf("%s already exists, pass -o to overwrite", filename)
182+
}
183+
}
169184

170185
if interactive {
171186
contents, err := ioutil.ReadFile(filename)

client/parser/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ func configPull(argv []string) error {
121121
usage := `
122122
Extract all environment variables from an application for local use.
123123
124-
Your environment will be stored locally in a file named .env. This file can be
124+
The environmental variables can be piped into a file, 'deis config:pull > file',
125+
or stored locally in a file named .env. This file can be
125126
read by foreman to load the local environment for your app.
126127
127128
Usage: deis config:pull [options]

0 commit comments

Comments
 (0)