Skip to content

Commit

Permalink
Merge pull request #299 from bacongobbler/config-list-diff
Browse files Browse the repository at this point in the history
feat(cmd): add config:list --diff
  • Loading branch information
Matthew Fisher authored Apr 3, 2017
2 parents 56742a9 + 89982ee commit 90df5f4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Commander interface {
CertInfo(string) error
CertAttach(string, string) error
CertDetach(string, string) error
ConfigList(string, bool) error
ConfigList(string, string) error
ConfigSet(string, []string) error
ConfigUnset(string, []string) error
ConfigPull(string, bool, bool) error
Expand Down
24 changes: 16 additions & 8 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

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

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

keys := sortKeys(config.Values)

if oneLine {
var configOutput *bytes.Buffer = new(bytes.Buffer)

switch format {
case "oneline":
for i, key := range keys {
sep := " "
if i == len(keys)-1 {
sep = "\n"
}
d.Printf("%s=%s%s", key, config.Values[key], sep)
fmt.Fprintf(configOutput, "%s=%s%s", key, config.Values[key], sep)
}
} else {
d.Printf("=== %s Config\n", appID)
case "diff":
for _, key := range keys {
fmt.Fprintf(configOutput, "%s=%s\n", key, config.Values[key])
}
default:
fmt.Fprintf(configOutput, "=== %s Config\n", appID)

configMap := make(map[string]string)

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

d.Print(prettyprint.PrettyTabs(configMap, 6))
fmt.Fprint(configOutput, prettyprint.PrettyTabs(configMap, 6))
}

d.Print(configOutput)
return nil
}

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

return d.ConfigList(appID, false)
return d.ConfigList(appID, "")
}

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

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

return d.ConfigList(appID, false)
return d.ConfigList(appID, "")
}

// ConfigPull pulls an app's config to a file.
Expand Down
10 changes: 8 additions & 2 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestConfigList(t *testing.T) {
var b bytes.Buffer
cmdr := DeisCmd{WOut: &b, ConfigFile: cf}

err = cmdr.ConfigList("foo", false)
err = cmdr.ConfigList("foo", "")
assert.NoErr(t, err)

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

err = cmdr.ConfigList("foo", true)
err = cmdr.ConfigList("foo", "oneline")
assert.NoErr(t, err)
assert.Equal(t, b.String(), "FLOAT=12.34 NCC=1701 TEST=testing TRUE=false\n", "output")

b.Reset()

err = cmdr.ConfigList("foo", "diff")
assert.NoErr(t, err)
assert.Equal(t, b.String(), "FLOAT=12.34\nNCC=1701\nTEST=testing\nTRUE=false\n", "output")
}

func TestConfigSet(t *testing.T) {
Expand Down
12 changes: 11 additions & 1 deletion parser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Usage: deis config:list [options]
Options:
--oneline
print output on one line.
--diff
print output on multiple lines for comparison against .env files.
-a --app=<app>
the uniquely identifiable name of the application.
`
Expand All @@ -65,8 +67,16 @@ Options:
}
app := safeGetValue(args, "--app")
oneline := args["--oneline"].(bool)
diff := args["--diff"].(bool)

return cmdr.ConfigList(app, oneline)
format := ""
if oneline {
format = "oneline"
} else if diff {
format = "diff"
}

return cmdr.ConfigList(app, format)
}

func configSet(argv []string, cmdr cmd.Commander) error {
Expand Down
2 changes: 1 addition & 1 deletion parser/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Create fake implementations of each method that return the argument
// we expect to have called the function (as an error to satisfy the interface).

func (d FakeDeisCmd) ConfigList(string, bool) error {
func (d FakeDeisCmd) ConfigList(string, string) error {
return errors.New("config:list")
}

Expand Down

0 comments on commit 90df5f4

Please sign in to comment.