Skip to content

Commit 34d297a

Browse files
committed
chore(workflow-cli): use k8s style output
1 parent 8ba7426 commit 34d297a

84 files changed

Lines changed: 1001 additions & 1077 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/apps.go

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111

1212
"github.com/drycc/controller-sdk-go/api"
1313
"github.com/drycc/controller-sdk-go/apps"
14+
"github.com/drycc/controller-sdk-go/appsettings"
1415
"github.com/drycc/controller-sdk-go/domains"
16+
"github.com/drycc/controller-sdk-go/ps"
1517
"github.com/drycc/workflow-cli/pkg/git"
1618
"github.com/drycc/workflow-cli/pkg/logging"
1719
"github.com/drycc/workflow-cli/pkg/webbrowser"
@@ -75,11 +77,20 @@ func (d *DryccCmd) AppsList(results int) error {
7577
if d.checkAPICompatibility(s.Client, err) != nil {
7678
return err
7779
}
78-
79-
d.Printf("=== Apps%s", limitCount(len(apps), count))
80-
81-
for _, app := range apps {
82-
d.Println(app.ID)
80+
if count > 0 {
81+
table := d.getDefaultFormatTable([]string{"ID", "UUID", "OWNER", "CREATED", "UPDATED"})
82+
for _, app := range apps {
83+
table.Append([]string{
84+
app.ID,
85+
app.UUID,
86+
app.Owner,
87+
app.Created,
88+
app.Updated,
89+
})
90+
}
91+
table.Render()
92+
} else {
93+
d.Println("No apps found.")
8394
}
8495
return nil
8596
}
@@ -102,38 +113,71 @@ func (d *DryccCmd) AppInfo(appID string) error {
102113
return err
103114
}
104115

105-
if url == "" {
106-
url = fmt.Sprintf(noDomainAssignedMsg, appID)
107-
}
108-
109-
d.Printf("=== %s Application\n", app.ID)
110-
d.Println("updated: ", app.Updated)
111-
d.Println("uuid: ", app.UUID)
112-
d.Println("created: ", app.Created)
113-
d.Println("url: ", url)
114-
d.Println("owner: ", app.Owner)
115-
d.Println("id: ", app.ID)
116+
table := d.getDefaultFormatTable([]string{})
117+
table.Append([]string{"App:", app.ID})
118+
table.Append([]string{"URL:", url})
119+
table.Append([]string{"UUID:", app.UUID})
120+
table.Append([]string{"Owner:", app.Owner})
121+
table.Append([]string{"Created:", app.Created})
122+
table.Append([]string{"Updated:", app.Updated})
116123

117-
d.Println()
118124
// print the app processes
119-
if err = d.PsList(app.ID, defaultLimit); err != nil {
125+
processes, _, err := ps.List(s.Client, appID, defaultLimit)
126+
if d.checkAPICompatibility(s.Client, err) != nil {
120127
return err
121128
}
122129

123-
d.Println()
124-
// print the app domains
125-
if err = d.DomainsList(app.ID, defaultLimit); err != nil {
126-
return err
130+
if len(processes) > 0 {
131+
table.Append([]string{"Processes:"})
132+
for index, process := range processes {
133+
table.Append([]string{"", "Name:", process.Name})
134+
table.Append([]string{"", "Release:", process.Release})
135+
table.Append([]string{"", "State:", process.State})
136+
table.Append([]string{"", "Type:", process.Type})
137+
table.Append([]string{"", "Started:", process.Started.Format("2006-01-02T15:04:05MST")})
138+
if len(processes) > index+1 {
139+
table.Append([]string{""})
140+
}
141+
}
142+
} else {
143+
table.Append([]string{"Processes:", safeGetString("")})
127144
}
128145

129-
d.Println()
130-
// print the app labels
131-
if err = d.LabelsList(app.ID); err != nil {
146+
domains, _, err := domains.List(s.Client, appID, defaultLimit)
147+
if d.checkAPICompatibility(s.Client, err) != nil {
132148
return err
133149
}
150+
if len(domains) > 0 {
151+
table.Append([]string{"Domains:"})
152+
for index, domain := range domains {
153+
table.Append([]string{"", "Domain:", domain.Domain})
154+
table.Append([]string{"", "Created:", domain.Created})
155+
table.Append([]string{"", "Updated:", domain.Updated})
156+
if len(domains) > index+1 {
157+
table.Append([]string{""})
158+
}
159+
}
160+
} else {
161+
table.Append([]string{"Domains:", safeGetString("")})
162+
}
134163

135-
d.Println()
136-
164+
appSettings, err := appsettings.List(s.Client, appID)
165+
if d.checkAPICompatibility(s.Client, err) != nil {
166+
return err
167+
}
168+
if len(appSettings.Label) > 0 {
169+
table.Append([]string{"Labels:"})
170+
for index, label := range *sortKeys(appSettings.Label) {
171+
table.Append([]string{"", "Key:", label})
172+
table.Append([]string{"", "Value:", fmt.Sprintf("%v", appSettings.Label[label])})
173+
if len(appSettings.Label) > index+1 {
174+
table.Append([]string{""})
175+
}
176+
}
177+
} else {
178+
table.Append([]string{"Labels:", safeGetString("")})
179+
}
180+
table.Render()
137181
return nil
138182
}
139183

@@ -306,7 +350,7 @@ func (d *DryccCmd) AppTransfer(appID, username string) error {
306350
return nil
307351
}
308352

309-
const noDomainAssignedMsg = "No domain assigned to %s"
353+
const noDomainAssignedMsg = "no domain assigned to %s"
310354

311355
// appURL grabs the first domain an app has and returns this.
312356
func (d *DryccCmd) appURL(s *settings.Settings, appID string) (string, error) {

cmd/apps_test.go

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
76
"net/http"
87
"os"
98
"testing"
@@ -63,9 +62,9 @@ func TestAppsList(t *testing.T) {
6362

6463
err = cmdr.AppsList(-1)
6564
assert.NoError(t, err)
66-
assert.Equal(t, b.String(), `=== Apps
67-
lorem-ipsum
68-
consectetur
65+
assert.Equal(t, b.String(), `ID UUID OWNER CREATED UPDATED
66+
lorem-ipsum c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 dolar-sit-amet 2016-08-22T17:40:16Z 2016-08-22T17:40:16Z
67+
consectetur c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 adipiscing 2016-08-22T17:40:16Z 2016-08-22T17:40:16Z
6968
`, "output")
7069
}
7170

@@ -102,8 +101,8 @@ func TestAppsListLimit(t *testing.T) {
102101

103102
err = cmdr.AppsList(1)
104103
assert.NoError(t, err)
105-
assert.Equal(t, b.String(), `=== Apps (1 of 2)
106-
lorem-ipsum
104+
assert.Equal(t, b.String(), `ID UUID OWNER CREATED UPDATED
105+
lorem-ipsum c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 dolar-sit-amet 2016-08-22T17:40:16Z 2016-08-22T17:40:16Z
107106
`, "output")
108107
}
109108

@@ -178,41 +177,35 @@ func TestAppsInfo(t *testing.T) {
178177
}
179178
}`)
180179
})
181-
182180
s, err := settings.Load(cmdr.ConfigFile)
183181
if err != nil {
184182
t.Fatal(err)
185183
}
186-
187184
url, err := cmdr.appURL(s, "lorem-ipsum")
188185
if err != nil {
189186
t.Fatal(err)
190187
}
191-
192-
if url == "" {
193-
url = fmt.Sprintf(noDomainAssignedMsg, "lorem-ipsum")
194-
}
195-
196188
err = cmdr.AppInfo("lorem-ipsum")
197189
assert.NoError(t, err)
198-
assert.Equal(t, b.String(), `=== lorem-ipsum Application
199-
updated: 2016-08-22T17:40:16Z
200-
uuid: c4aed81c-d1ca-4ff1-ab89-d2151264e1a3
201-
created: 2016-08-22T17:40:16Z
202-
url: `+url+`
203-
owner: dolar-sit-amet
204-
id: lorem-ipsum
205-
206-
=== lorem-ipsum Processes
207-
--- cmd:
208-
lorem-ipsum-cmd-1911796442-48b58 up (v2)
209-
210-
=== lorem-ipsum Domains
211-
lorem-ipsum
212-
213-
=== lorem-ipsum Label
214-
team: frontend
215-
190+
assert.Equal(t, b.String(), `App: lorem-ipsum
191+
URL: `+url+`
192+
UUID: c4aed81c-d1ca-4ff1-ab89-d2151264e1a3
193+
Owner: dolar-sit-amet
194+
Created: 2016-08-22T17:40:16Z
195+
Updated: 2016-08-22T17:40:16Z
196+
Processes:
197+
Name: lorem-ipsum-cmd-1911796442-48b58
198+
Release: v2
199+
State: up
200+
Type: cmd
201+
Started: 2016-08-22T17:42:16UTC
202+
Domains:
203+
Domain: lorem-ipsum
204+
Created: 2016-08-22T17:40:16Z
205+
Updated: 2016-08-22T17:40:16Z
206+
Labels:
207+
Key: team
208+
Value: frontend
216209
`, "output")
217210
}
218211

@@ -319,7 +312,7 @@ func TestRemoteExists(t *testing.T) {
319312
})
320313

321314
// create a remote first before running apps:create
322-
dir, err := ioutil.TempDir("", "apps")
315+
dir, err := os.MkdirTemp("", "apps")
323316
assert.NoError(t, err)
324317

325318
defer os.RemoveAll(dir)

cmd/autoscale.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package cmd
22

33
import (
4+
"fmt"
5+
46
"github.com/drycc/controller-sdk-go/api"
57
"github.com/drycc/controller-sdk-go/appsettings"
68
)
@@ -17,16 +19,20 @@ func (d *DryccCmd) AutoscaleList(appID string) error {
1719
if d.checkAPICompatibility(s.Client, err) != nil {
1820
return err
1921
}
20-
21-
d.Printf("=== %s Autoscale\n\n", appID)
22-
2322
if appSettings.Autoscale == nil {
2423
d.Println("No autoscale rules found.")
2524
} else {
25+
table := d.getDefaultFormatTable([]string{"UUID", "TYPE", "PERCENT", "MIN", "MAX"})
2626
for process, kv := range appSettings.Autoscale {
27-
d.Println("--- " + process + ":")
28-
d.Println(*kv)
27+
table.Append([]string{
28+
appSettings.UUID,
29+
process,
30+
fmt.Sprintf("%d", (*kv).CPUPercent),
31+
fmt.Sprintf("%d", (*kv).Min),
32+
fmt.Sprintf("%d", (*kv).Max),
33+
})
2934
}
35+
table.Render()
3036
}
3137

3238
return nil

cmd/autoscale_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ func TestAutoscaleList(t *testing.T) {
3535

3636
err = cmdr.AutoscaleList("rivendell")
3737
assert.NoError(t, err)
38-
assert.Equal(t, b.String(), "=== rivendell Autoscale\n\n--- cmd:\nMin Replicas: 3\nMax Replicas: 8\nCPU: 40%\n", "output")
38+
assert.Equal(t, b.String(), `UUID TYPE PERCENT MIN MAX
39+
de1bf5b5-4a72-4f94-a10c-d2a3741cdf75 cmd 40 3 8
40+
`, "output")
3941

4042
server.Mux.HandleFunc("/v2/apps/mordor/settings/", func(w http.ResponseWriter, r *http.Request) {
4143
testutil.SetHeaders(w)
@@ -51,7 +53,7 @@ func TestAutoscaleList(t *testing.T) {
5153

5254
err = cmdr.AutoscaleList("mordor")
5355
assert.NoError(t, err)
54-
assert.Equal(t, b.String(), "=== mordor Autoscale\n\nNo autoscale rules found.\n", "output")
56+
assert.Equal(t, b.String(), "No autoscale rules found.\n", "output")
5557
}
5658

5759
func TestAutoscaleSet(t *testing.T) {

cmd/builds.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"io/ioutil"
4+
"fmt"
55
"os"
66

77
yaml "gopkg.in/yaml.v3"
@@ -25,11 +25,19 @@ func (d *DryccCmd) BuildsList(appID string, results int) error {
2525
if d.checkAPICompatibility(s.Client, err) != nil {
2626
return err
2727
}
28-
29-
d.Printf("=== %s Builds%s", appID, limitCount(len(builds), count))
30-
31-
for _, build := range builds {
32-
d.Println(build.UUID, build.Created)
28+
if count > 0 {
29+
table := d.getDefaultFormatTable([]string{"UUID", "OWNER", "SHA", "CREATED"})
30+
for _, build := range builds {
31+
table.Append([]string{
32+
build.UUID,
33+
safeGetString(build.Owner),
34+
safeGetString(build.Sha),
35+
build.Created,
36+
})
37+
}
38+
table.Render()
39+
} else {
40+
d.Println(fmt.Sprintf("No builds found in %s app.", appID))
3341
}
3442
return nil
3543
}
@@ -49,7 +57,7 @@ func (d *DryccCmd) BuildsCreate(appID, image, stack, procfile string) error {
4957
return err
5058
}
5159
} else if _, err := os.Stat("Procfile"); err == nil {
52-
contents, err := ioutil.ReadFile("Procfile")
60+
contents, err := os.ReadFile("Procfile")
5361
if err != nil {
5462
return err
5563
}

cmd/builds_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
76
"net/http"
87
"os"
98
"testing"
@@ -73,9 +72,9 @@ func TestBuildsList(t *testing.T) {
7372

7473
err = cmdr.BuildsList("foo", -1)
7574
assert.NoError(t, err)
76-
assert.Equal(t, b.String(), `=== foo Builds
77-
de1bf5b5-4a72-4f94-a10c-d2a3741cdf75 2014-01-01T00:00:00UTC
78-
c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 2014-01-05T00:00:00UTC
75+
assert.Equal(t, b.String(), `UUID OWNER SHA CREATED
76+
de1bf5b5-4a72-4f94-a10c-d2a3741cdf75 <none> <none> 2014-01-01T00:00:00UTC
77+
c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 <none> <none> 2014-01-05T00:00:00UTC
7978
`, "output")
8079
}
8180

@@ -113,8 +112,8 @@ func TestBuildsListLimit(t *testing.T) {
113112

114113
err = cmdr.BuildsList("foo", 1)
115114
assert.NoError(t, err)
116-
assert.Equal(t, b.String(), `=== foo Builds (1 of 2)
117-
de1bf5b5-4a72-4f94-a10c-d2a3741cdf75 2014-01-01T00:00:00UTC
115+
assert.Equal(t, b.String(), `UUID OWNER SHA CREATED
116+
de1bf5b5-4a72-4f94-a10c-d2a3741cdf75 <none> <none> 2014-01-01T00:00:00UTC
118117
`, "output")
119118
}
120119

@@ -129,7 +128,7 @@ func TestBuildsCreate(t *testing.T) {
129128
cmdr := DryccCmd{WOut: &b, ConfigFile: cf}
130129

131130
// Create a new temporary directory and change to it.
132-
name, err := ioutil.TempDir("", "client")
131+
name, err := os.MkdirTemp("", "client")
133132
assert.NoError(t, err)
134133
err = os.Chdir(name)
135134
assert.NoError(t, err)
@@ -186,7 +185,7 @@ warp: ./warp 8
186185
})
187186
b.Reset()
188187

189-
err = ioutil.WriteFile("Procfile", []byte(`web: ./drive
188+
err = os.WriteFile("Procfile", []byte(`web: ./drive
190189
warp: ./warp 8
191190
`), os.ModePerm)
192191
assert.NoError(t, err)

0 commit comments

Comments
 (0)