mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00

This commit moves monitor commands to `monior/commands` package. Commands still need access to the `monitor` object and buildx controller so this commit enables this via `Monitor` interface stored in `monitor/types`. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
41 lines
773 B
Go
41 lines
773 B
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"sort"
|
|
"text/tabwriter"
|
|
|
|
"github.com/docker/buildx/monitor/types"
|
|
)
|
|
|
|
type ListCmd struct {
|
|
m types.Monitor
|
|
|
|
stdout io.WriteCloser
|
|
}
|
|
|
|
func NewListCmd(m types.Monitor, stdout io.WriteCloser) types.Command {
|
|
return &ListCmd{m, stdout}
|
|
}
|
|
|
|
func (cm *ListCmd) Info() types.CommandInfo {
|
|
return types.CommandInfo{HelpMessage: "list buildx sessions"}
|
|
}
|
|
|
|
func (cm *ListCmd) Exec(ctx context.Context, args []string) error {
|
|
refs, err := cm.m.List(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sort.Strings(refs)
|
|
tw := tabwriter.NewWriter(cm.stdout, 1, 8, 1, '\t', 0)
|
|
fmt.Fprintln(tw, "ID\tCURRENT_SESSION")
|
|
for _, k := range refs {
|
|
fmt.Fprintf(tw, "%-20s\t%v\n", k, k == cm.m.AttachedSessionID())
|
|
}
|
|
tw.Flush()
|
|
return nil
|
|
}
|