feat: finish ps command
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
ce5a03d579
commit
ff0b0b5ad8
2
TODO.md
2
TODO.md
@ -23,7 +23,7 @@
|
|||||||
- [ ] `config`
|
- [ ] `config`
|
||||||
- [ ] `cp`
|
- [ ] `cp`
|
||||||
- [ ] `logs`
|
- [ ] `logs`
|
||||||
- [ ] `ps` (WIP: decentral1se)
|
- [x] `ps`
|
||||||
- [ ] `restore`
|
- [ ] `restore`
|
||||||
- [x] `rm`
|
- [x] `rm`
|
||||||
- [ ] `run`
|
- [ ] `run`
|
||||||
|
@ -2,16 +2,16 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
abraFormatter "coopcloud.tech/abra/cli/formatter"
|
abraFormatter "coopcloud.tech/abra/cli/formatter"
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/client"
|
"coopcloud.tech/abra/client"
|
||||||
|
"coopcloud.tech/abra/config"
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
"github.com/docker/cli/cli/command/formatter"
|
||||||
"github.com/docker/cli/cli/command/idresolver"
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
@ -19,31 +19,41 @@ import (
|
|||||||
var appPsCommand = &cli.Command{
|
var appPsCommand = &cli.Command{
|
||||||
Name: "ps",
|
Name: "ps",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
appName := c.Args().First()
|
||||||
|
if appName == "" {
|
||||||
|
internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided"))
|
||||||
|
}
|
||||||
|
|
||||||
|
appFiles, err := config.LoadAppFiles("")
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
host := appFiles[appName].Server
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cl, err := client.NewClientWithContext(internal.Context)
|
cl, err := client.NewClientWithContext(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
tasks, err := cl.TaskList(ctx, types.TaskListOptions{})
|
|
||||||
|
appEnv, err := config.GetApp(appFiles, appName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
for _, task := range tasks {
|
|
||||||
resolver := idresolver.New(cl, false)
|
filters := filters.NewArgs()
|
||||||
serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID)
|
filters.Add("name", appEnv.StackName())
|
||||||
if err != nil {
|
|
||||||
return err
|
containers, err := cl.ContainerList(ctx, types.ContainerListOptions{Filters: filters})
|
||||||
}
|
|
||||||
fmt.Printf("%#v\n", serviceName)
|
|
||||||
}
|
|
||||||
containers, err := cl.ContainerList(ctx, types.ContainerListOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
table := abraFormatter.CreateTable([]string{"ID", "Image", "Command", "Created", "Status", "Ports", "Names"})
|
|
||||||
var conTable [][]string
|
tableCol := []string{"ID", "Image", "Command", "Created", "Status", "Ports", "Names"}
|
||||||
|
table := abraFormatter.CreateTable(tableCol)
|
||||||
|
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
conRow := []string{
|
tableRow := []string{
|
||||||
abraFormatter.ShortenID(container.ID),
|
abraFormatter.ShortenID(container.ID),
|
||||||
abraFormatter.RemoveSha(container.Image),
|
abraFormatter.RemoveSha(container.Image),
|
||||||
abraFormatter.Truncate(container.Command),
|
abraFormatter.Truncate(container.Command),
|
||||||
@ -52,9 +62,9 @@ var appPsCommand = &cli.Command{
|
|||||||
formatter.DisplayablePorts(container.Ports),
|
formatter.DisplayablePorts(container.Ports),
|
||||||
strings.Join(container.Names, ","),
|
strings.Join(container.Names, ","),
|
||||||
}
|
}
|
||||||
conTable = append(conTable, conRow)
|
table.Append(tableRow)
|
||||||
}
|
}
|
||||||
table.AppendBulk(conTable)
|
|
||||||
table.Render()
|
table.Render()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user