-
Notifications
You must be signed in to change notification settings - Fork 26
/
version.go
50 lines (41 loc) · 1.25 KB
/
version.go
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
package cmd
import (
"fmt"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/aserto-dev/topaz/pkg/cli/dockerx"
"github.com/aserto-dev/topaz/pkg/cli/x"
"github.com/aserto-dev/topaz/pkg/version"
)
type VersionCmd struct {
Container bool `short:"c" help:"display topazd container version" default:"false"`
ContainerName string `optional:"" default:"topaz" help:"container name"`
ContainerVersion string `optional:"" default:"latest" help:"container version"`
Platform string `optional:"" default:"linux/amd64" help:"set platform if server is multi-platform capable"`
}
func (cmd *VersionCmd) Run(c *cc.CommonCtx) error {
fmt.Fprintf(c.UI.Output(), "%s %s\n",
x.AppName,
version.GetInfo().String(),
)
if !cmd.Container {
return nil
}
env := map[string]string{}
// default command
// docker run -ti --rm --name topazd-version --platform=linux/arm64 ghcr.io/aserto-dev/topaz:latest version
args := []string{
"run",
"-ti",
"--rm",
"--name", "topazd-version",
"--platform=" + cmd.Platform,
"ghcr.io/aserto-dev/" + cmd.ContainerName + ":" + cmd.ContainerVersion,
"version",
}
result, err := dockerx.DockerWithOut(env, args...)
if err != nil {
return err
}
fmt.Fprintf(c.UI.Output(), "%s\n", result)
return nil
}