Skip to content

Commit cb8f4f5

Browse files
authored
Merge pull request #8 from jianxiaoguo/master
feat(ps):add ps:stop/start command pretty print
2 parents 370f010 + 56284d3 commit cb8f4f5

2 files changed

Lines changed: 26 additions & 24 deletions

File tree

ps/ps.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,13 @@ func ByType(processes api.PodsList) api.PodTypes {
127127

128128
// Is processtype for process doesn't exist, create a new one
129129
if !exists {
130-
p := api.PodsList{}
131-
status := "stopped"
132-
if process.Name != "" {
133-
p = api.PodsList{process}
134-
status = "started"
130+
p := api.PodsList{process}
131+
status := "started"
132+
if process.State == "stopped" && process.Replicas != 0 {
133+
status = "stopped"
134+
}
135+
if process.Name == "" {
136+
p = api.PodsList{}
135137
}
136138
pts = append(pts, api.PodType{
137139
Type: process.Type,

ps/ps_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ func TestByType(t *testing.T) {
359359
{
360360
Type: "abc",
361361
PodsList: api.PodsList{
362-
{Type: "abc", Name: "1", Started: started, Replicas: 3},
363-
{Type: "abc", Name: "2", Started: started, Replicas: 3},
364-
{Type: "abc", Name: "3", Started: started, Replicas: 3},
362+
{Type: "abc", Name: "1", Started: started, Replicas: 3, State: "up"},
363+
{Type: "abc", Name: "2", Started: started, Replicas: 3, State: "up"},
364+
{Type: "abc", Name: "3", Started: started, Replicas: 3, State: "up"},
365365
},
366366
Replicas: 3,
367367
Status: "started",
@@ -375,36 +375,36 @@ func TestByType(t *testing.T) {
375375
{
376376
Type: "web",
377377
PodsList: api.PodsList{
378-
{Type: "web", Name: "test1", Started: started, Replicas: 3},
379-
{Type: "web", Name: "test2", Started: started, Replicas: 3},
380-
{Type: "web", Name: "test3", Started: started, Replicas: 3},
378+
{Type: "web", Name: "test1", Started: started, Replicas: 3, State: "up"},
379+
{Type: "web", Name: "test2", Started: started, Replicas: 3, State: "up"},
380+
{Type: "web", Name: "test3", Started: started, Replicas: 3, State: "up"},
381381
},
382382
Replicas: 3,
383383
Status: "started",
384384
},
385385
{
386386
Type: "worker",
387387
PodsList: api.PodsList{
388-
{Type: "worker", Name: "a", Started: started, Replicas: 3},
389-
{Type: "worker", Name: "b", Started: started, Replicas: 3},
390-
{Type: "worker", Name: "c", Started: started, Replicas: 3},
388+
{Type: "worker", Name: "a", Started: started, Replicas: 3, State: "up"},
389+
{Type: "worker", Name: "b", Started: started, Replicas: 3, State: "up"},
390+
{Type: "worker", Name: "c", Started: started, Replicas: 3, State: "up"},
391391
},
392392
Replicas: 3,
393393
Status: "started",
394394
},
395395
}
396396

397397
input := api.PodsList{
398-
{Type: "worker", Name: "c", Started: started, Replicas: 3},
399-
{Type: "abc", Name: "2", Started: started, Replicas: 3},
400-
{Type: "worker", Name: "b", Started: started, Replicas: 3},
401-
{Type: "web", Name: "test1", Started: started, Replicas: 3},
402-
{Type: "web", Name: "test3", Started: started, Replicas: 3},
403-
{Type: "abc", Name: "1", Started: started, Replicas: 3},
404-
{Type: "worker", Name: "a", Started: started, Replicas: 3},
405-
{Type: "abc", Name: "3", Started: started, Replicas: 3},
406-
{Type: "web", Name: "test2", Started: started, Replicas: 3},
407-
{Type: "job", Replicas: 3},
398+
{Type: "worker", Name: "c", Started: started, Replicas: 3, State: "up"},
399+
{Type: "abc", Name: "2", Started: started, Replicas: 3, State: "up"},
400+
{Type: "worker", Name: "b", Started: started, Replicas: 3, State: "up"},
401+
{Type: "web", Name: "test1", Started: started, Replicas: 3, State: "up"},
402+
{Type: "web", Name: "test3", Started: started, Replicas: 3, State: "up"},
403+
{Type: "abc", Name: "1", Started: started, Replicas: 3, State: "up"},
404+
{Type: "worker", Name: "a", Started: started, Replicas: 3, State: "up"},
405+
{Type: "abc", Name: "3", Started: started, Replicas: 3, State: "up"},
406+
{Type: "web", Name: "test2", Started: started, Replicas: 3, State: "up"},
407+
{Type: "job", Replicas: 3, State: "stopped"},
408408
}
409409

410410
actual := ByType(input)

0 commit comments

Comments
 (0)