This commit is contained in:
david 2024-03-02 00:14:14 +08:00
parent f1e51a41ef
commit 4033869b5d
3 changed files with 20 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import (
"git.apinb.com/bsm-sdk/engine/env"
"git.apinb.com/bsm-sdk/engine/utils"
"git.apinb.com/bsm-sdk/engine/vars"
"github.com/golistic/boxed"
"github.com/modood/table"
"github.com/spf13/cobra"
)
@ -40,6 +41,7 @@ type PsTable struct {
ServiceKey string `table:"Service Key"`
Origin string
Status string
PID string
Performance string
CurrentVersion string `table:"Current Version"`
RegisterVersion string `table:"Register Version"`
@ -79,6 +81,19 @@ func psExecute() {
// Output to stdout
table.Output(pt)
print(pt)
}
func print(pt []PsTable) {
box := boxed.New()
_ = box.AddHeader("Service Key", "Origin", "Status", "PID", "Performance", "Local Version", "Registry Version", "Updated At")
for _, v := range pt {
_ = box.Append(
boxed.NewRow(v.ServiceKey, v.Origin, v.Status, v.PID, v.Performance, v.CurrentVersion, v.RegisterVersion, v.UpdatedAt))
}
_ = box.Render()
}
func getSrvStatus(srv string) PsTable {
@ -94,11 +109,12 @@ func getSrvStatus(srv string) PsTable {
status = "\033[31mStop\033[0m\n"
}
_, cm := getProcessInfo(srv)
pid, cm := getProcessInfo(srv)
return PsTable{
Status: status,
CurrentVersion: getCurrentVersion(srv),
PID: pid,
Performance: cm,
}

1
go.mod
View File

@ -10,6 +10,7 @@ require (
)
require (
github.com/golistic/boxed v0.0.0-20231227175750-bd89723124e7
github.com/google/uuid v1.6.0 // indirect
github.com/jaevor/go-nanoid v1.3.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect

2
go.sum
View File

@ -1,6 +1,8 @@
git.apinb.com/bsm-sdk/engine v1.0.9 h1:3zPYp8wtBVi7Aeg3H3/q7ZSVDRsGiXxQXwNzyMxfhao=
git.apinb.com/bsm-sdk/engine v1.0.9/go.mod h1:zCJfxj6RHHVHQmDn+Z2qa5s1qU7a3rTL9AZqEja9vIc=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/golistic/boxed v0.0.0-20231227175750-bd89723124e7 h1:nof2QnZZ42zxwzrWFK/e8CMaN/AXgGX7AGJ/pb8RgBk=
github.com/golistic/boxed v0.0.0-20231227175750-bd89723124e7/go.mod h1:FB8Aa5H1xlLhPbpXIfP9JcwTt287TCI29X4xCEXaIBg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=