Skip to content

Commit 89982ee

Browse files
author
Matthew Fisher
committed
feat(cmd): add config:list --diff
1 parent 1ffbad5 commit 89982ee

5 files changed

Lines changed: 37 additions & 13 deletions

File tree

cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Commander interface {
3636
CertInfo(string) error
3737
CertAttach(string, string) error
3838
CertDetach(string, string) error
39-
ConfigList(string, bool) error
39+
ConfigList(string, string) error
4040
ConfigSet(string, []string) error
4141
ConfigUnset(string, []string) error
4242
ConfigPull(string, bool, bool) error

cmd/config.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
// ConfigList lists an app's config.
20-
func (d *DeisCmd) ConfigList(appID string, oneLine bool) error {
20+
func (d *DeisCmd) ConfigList(appID string, format string) error {
2121
s, appID, err := load(d.ConfigFile, appID)
2222

2323
if err != nil {
@@ -31,16 +31,23 @@ func (d *DeisCmd) ConfigList(appID string, oneLine bool) error {
3131

3232
keys := sortKeys(config.Values)
3333

34-
if oneLine {
34+
var configOutput *bytes.Buffer = new(bytes.Buffer)
35+
36+
switch format {
37+
case "oneline":
3538
for i, key := range keys {
3639
sep := " "
3740
if i == len(keys)-1 {
3841
sep = "\n"
3942
}
40-
d.Printf("%s=%s%s", key, config.Values[key], sep)
43+
fmt.Fprintf(configOutput, "%s=%s%s", key, config.Values[key], sep)
4144
}
42-
} else {
43-
d.Printf("=== %s Config\n", appID)
45+
case "diff":
46+
for _, key := range keys {
47+
fmt.Fprintf(configOutput, "%s=%s\n", key, config.Values[key])
48+
}
49+
default:
50+
fmt.Fprintf(configOutput, "=== %s Config\n", appID)
4451

4552
configMap := make(map[string]string)
4653

@@ -49,9 +56,10 @@ func (d *DeisCmd) ConfigList(appID string, oneLine bool) error {
4956
configMap[key] = fmt.Sprintf("%v", config.Values[key])
5057
}
5158

52-
d.Print(prettyprint.PrettyTabs(configMap, 6))
59+
fmt.Fprint(configOutput, prettyprint.PrettyTabs(configMap, 6))
5360
}
5461

62+
d.Print(configOutput)
5563
return nil
5664
}
5765

@@ -119,7 +127,7 @@ to set up healthchecks. This functionality has been deprecated. In the future, p
119127
d.Print("done\n\n")
120128
}
121129

122-
return d.ConfigList(appID, false)
130+
return d.ConfigList(appID, "")
123131
}
124132

125133
// ConfigUnset removes a config variable from an app.
@@ -153,7 +161,7 @@ func (d *DeisCmd) ConfigUnset(appID string, configVars []string) error {
153161

154162
d.Print("done\n\n")
155163

156-
return d.ConfigList(appID, false)
164+
return d.ConfigList(appID, "")
157165
}
158166

159167
// ConfigPull pulls an app's config to a file.

cmd/config_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestConfigList(t *testing.T) {
8787
var b bytes.Buffer
8888
cmdr := DeisCmd{WOut: &b, ConfigFile: cf}
8989

90-
err = cmdr.ConfigList("foo", false)
90+
err = cmdr.ConfigList("foo", "")
9191
assert.NoErr(t, err)
9292

9393
assert.Equal(t, b.String(), `=== foo Config
@@ -98,9 +98,15 @@ TRUE false
9898
`, "output")
9999
b.Reset()
100100

101-
err = cmdr.ConfigList("foo", true)
101+
err = cmdr.ConfigList("foo", "oneline")
102102
assert.NoErr(t, err)
103103
assert.Equal(t, b.String(), "FLOAT=12.34 NCC=1701 TEST=testing TRUE=false\n", "output")
104+
105+
b.Reset()
106+
107+
err = cmdr.ConfigList("foo", "diff")
108+
assert.NoErr(t, err)
109+
assert.Equal(t, b.String(), "FLOAT=12.34\nNCC=1701\nTEST=testing\nTRUE=false\n", "output")
104110
}
105111

106112
func TestConfigSet(t *testing.T) {

parser/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Usage: deis config:list [options]
5454
Options:
5555
--oneline
5656
print output on one line.
57+
--diff
58+
print output on multiple lines for comparison against .env files.
5759
-a --app=<app>
5860
the uniquely identifiable name of the application.
5961
`
@@ -65,8 +67,16 @@ Options:
6567
}
6668
app := safeGetValue(args, "--app")
6769
oneline := args["--oneline"].(bool)
70+
diff := args["--diff"].(bool)
6871

69-
return cmdr.ConfigList(app, oneline)
72+
format := ""
73+
if oneline {
74+
format = "oneline"
75+
} else if diff {
76+
format = "diff"
77+
}
78+
79+
return cmdr.ConfigList(app, format)
7080
}
7181

7282
func configSet(argv []string, cmdr cmd.Commander) error {

parser/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// Create fake implementations of each method that return the argument
1313
// we expect to have called the function (as an error to satisfy the interface).
1414

15-
func (d FakeDeisCmd) ConfigList(string, bool) error {
15+
func (d FakeDeisCmd) ConfigList(string, string) error {
1616
return errors.New("config:list")
1717
}
1818

0 commit comments

Comments
 (0)