docker.go 969 Bytes
Newer Older
songlinfeng's avatar
songlinfeng committed
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
52
53
54
package docker

import (
	"dcu-container-toolkit/internal/logger"
	"dcu-container-toolkit/internal/query"
	"github.com/urfave/cli/v2"
)

type command struct {
	logger logger.Interface
}

type config struct {
	dcus string
}

func NewCommand(logger logger.Interface) *cli.Command {
	c := command{
		logger: logger,
	}
	return c.build()
}

func (m command) build() *cli.Command {
	cfg := config{}
	docker := cli.Command{
		Name:  "docker",
		Usage: "List which dockers are using the DCUs",
		Action: func(context *cli.Context) error {
			return m.run(context, &cfg)
		},
	}

	flags := []cli.Flag{
		&cli.StringFlag{
			Name:        "dcus",
			Aliases:     []string{"d"},
			Value:       "all",
			Usage:       "Show all DCUs, including those not in use",
			Destination: &cfg.dcus,
		},
	}
	docker.Flags = flags
	return &docker
}

func (m command) run(c *cli.Context, cfg *config) error {
	err := query.ShowStatus(cfg.dcus)
	if err != nil {
		return err
	}
	return nil
}