Skip to content

Commit 081662b

Browse files
committed
chore(config): beautify the config list format
1 parent 7025b48 commit 081662b

2 files changed

Lines changed: 38 additions & 55 deletions

File tree

cmd/config.go

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,15 @@ func (d *DryccCmd) ConfigList(appID string, ptype string) error {
2727
return err
2828
}
2929

30-
configValues := config.Values
31-
if ptype != "" {
32-
configValues = config.TypedValues[ptype]
33-
}
34-
35-
keys := *sortKeys(configValues)
36-
table := d.getDefaultFormatTable([]string{"NAME", "VALUE"})
37-
38-
for _, key := range keys {
39-
table.Append([]string{
40-
key,
41-
fmt.Sprintf("%v", configValues[key]),
42-
})
43-
}
44-
45-
// common config
46-
if ptype != "" {
47-
table.Append([]string{"--- Common Config:"})
48-
configValues = config.Values
49-
keys = *sortKeys(configValues)
50-
for _, key := range keys {
51-
table.Append([]string{
52-
key,
53-
fmt.Sprintf("%v", configValues[key]),
54-
})
30+
table := d.getDefaultFormatTable([]string{"PTYPE", "NAME", "VALUE"})
31+
for _, key := range *sortKeys(config.Values) {
32+
table.Append([]string{"N/A", key, fmt.Sprintf("%v", config.Values[key])})
33+
}
34+
for key, values := range config.TypedValues {
35+
if ptype == "" || ptype == key {
36+
for _, key2 := range *sortKeys(values) {
37+
table.Append([]string{key, key2, fmt.Sprintf("%v", values[key2])})
38+
}
5539
}
5640
}
5741
table.Render()

cmd/config_test.go

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,23 @@ func TestConfigList(t *testing.T) {
126126
err = cmdr.ConfigList("foo", "")
127127
assert.NoError(t, err)
128128

129-
assert.Equal(t, b.String(), `NAME VALUE
130-
FLOAT 12.34
131-
NCC 1701
132-
TEST testing
133-
TRUE false
129+
assert.Equal(t, b.String(), `PTYPE NAME VALUE
130+
N/A FLOAT 12.34
131+
N/A NCC 1701
132+
N/A TEST testing
133+
N/A TRUE false
134+
web PORT 9000
134135
`, "output")
135136

136137
b.Reset()
137138
err = cmdr.ConfigList("foo", "web")
138139
assert.NoError(t, err)
139-
assert.Equal(t, b.String(), `NAME VALUE
140-
PORT 9000
141-
--- Common Config:
142-
FLOAT 12.34
143-
NCC 1701
144-
TEST testing
145-
TRUE false
140+
assert.Equal(t, b.String(), `PTYPE NAME VALUE
141+
N/A FLOAT 12.34
142+
N/A NCC 1701
143+
N/A TEST testing
144+
N/A TRUE false
145+
web PORT 9000
146146
`, "output")
147147

148148
}
@@ -194,12 +194,12 @@ func TestConfigSet(t *testing.T) {
194194

195195
assert.Equal(t, testutil.StripProgress(b.String()), `Creating config... done
196196
197-
NAME VALUE
198-
FLOAT 12.34
199-
NCC 1701
200-
SSH_KEY LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0=
201-
TEST testing
202-
TRUE false
197+
PTYPE NAME VALUE
198+
N/A FLOAT 12.34
199+
N/A NCC 1701
200+
N/A SSH_KEY LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0=
201+
N/A TEST testing
202+
N/A TRUE false
203203
`, "output")
204204
}
205205

@@ -248,11 +248,11 @@ func TestConfigUnset(t *testing.T) {
248248

249249
assert.Equal(t, testutil.StripProgress(b.String()), `Removing config... done
250250
251-
NAME VALUE
252-
FLOAT 12.34
253-
NCC 1701
254-
TEST testing
255-
TRUE false
251+
PTYPE NAME VALUE
252+
N/A FLOAT 12.34
253+
N/A NCC 1701
254+
N/A TEST testing
255+
N/A TRUE false
256256
`, "output")
257257
}
258258

@@ -308,12 +308,11 @@ func TestConfigUnsetTypedValues(t *testing.T) {
308308

309309
assert.Equal(t, testutil.StripProgress(b.String()), `Removing config... done
310310
311-
NAME VALUE
312-
FLOAT 12.34
313-
NCC 1701
314-
TEST testing
315-
TRUE false
316-
--- Common Config:
317-
RELEASE_VERSION v1
311+
PTYPE NAME VALUE
312+
N/A RELEASE_VERSION v1
313+
web FLOAT 12.34
314+
web NCC 1701
315+
web TEST testing
316+
web TRUE false
318317
`, "output")
319318
}

0 commit comments

Comments
 (0)