forked from toolshed/abra
		
	feat: service name in ps output
This commit is contained in:
		| @ -9,6 +9,7 @@ import ( | ||||
| 	"coopcloud.tech/abra/pkg/client" | ||||
| 	"coopcloud.tech/abra/pkg/config" | ||||
| 	"coopcloud.tech/abra/pkg/formatter" | ||||
| 	"coopcloud.tech/abra/pkg/service" | ||||
| 	stack "coopcloud.tech/abra/pkg/upstream/stack" | ||||
| 	"github.com/buger/goterm" | ||||
| 	dockerFormatter "github.com/docker/cli/cli/command/formatter" | ||||
| @ -70,7 +71,7 @@ func showPSOutput(c *cli.Context, app config.App, cl *dockerClient.Client) { | ||||
| 		logrus.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	tableCol := []string{"image", "created", "status", "state", "ports"} | ||||
| 	tableCol := []string{"service name", "image", "created", "status", "state", "ports"} | ||||
| 	table := formatter.CreateTable(tableCol) | ||||
|  | ||||
| 	for _, container := range containers { | ||||
| @ -81,6 +82,7 @@ func showPSOutput(c *cli.Context, app config.App, cl *dockerClient.Client) { | ||||
| 		} | ||||
|  | ||||
| 		tableRow := []string{ | ||||
| 			service.ContainerToServiceName(container.Names, app.StackName()), | ||||
| 			formatter.RemoveSha(container.Image), | ||||
| 			formatter.HumanDuration(container.Created), | ||||
| 			container.Status, | ||||
|  | ||||
| @ -67,3 +67,12 @@ func GetService(c context.Context, cl *client.Client, filters filters.Args, prom | ||||
|  | ||||
| 	return services[0], nil | ||||
| } | ||||
|  | ||||
| // ContainerToServiceName converts a container name to a service name. | ||||
| func ContainerToServiceName(containerNames []string, stackName string) string { | ||||
| 	containerName := strings.Join(containerNames, "") | ||||
| 	trimmed := strings.TrimPrefix(containerName, "/") | ||||
| 	stackNameServiceName := strings.Split(trimmed, ".")[0] | ||||
| 	splitter := fmt.Sprintf("%s_", stackName) | ||||
| 	return strings.Split(stackNameServiceName, splitter)[1] | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user