forked from rancher/rio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps.go
51 lines (41 loc) · 923 Bytes
/
ps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ps
import (
"strings"
"github.com/pkg/errors"
"github.com/rancher/rio/cli/cmd/revision"
"github.com/rancher/rio/cli/pkg/clicontext"
"github.com/rancher/rio/cli/pkg/table"
"github.com/urfave/cli"
)
type Ps struct {
C_Containers bool `desc:"print containers, not services"`
}
func (p *Ps) Customize(cmd *cli.Command) {
cmd.Flags = append(table.WriterFlags(), cmd.Flags...)
}
func (p *Ps) Run(ctx *clicontext.CLIContext) error {
args := ctx.CLI.Args()
if len(args) == 0 {
if p.C_Containers {
return Containers(ctx)
}
return p.apps(ctx)
}
isRevision := true
for _, arg := range args {
if strings.Contains(arg, ":") {
isRevision = false
continue
}
if !isRevision {
return errors.New("Can not pass both service and revision")
}
}
if isRevision && !p.C_Containers {
return revision.Revisions(ctx)
}
if p.C_Containers {
return Containers(ctx)
}
return Pods(ctx)
}