-
Notifications
You must be signed in to change notification settings - Fork 26
/
cli.go
61 lines (52 loc) · 1.88 KB
/
cli.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
51
52
53
54
55
56
57
58
59
60
61
package cmd
import (
"errors"
"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"
)
var ErrNotRunning = errors.New("topaz is not running, use 'topaz start' or 'topaz run' to start")
type CLI struct {
Start StartCmd `cmd:"" help:"start topaz in daemon mode"`
Stop StopCmd `cmd:"" help:"stop topaz instance"`
Status StatusCmd `cmd:"" help:"status of topaz daemon process"`
Run RunCmd `cmd:"" help:"run topaz in console mode"`
Load LoadCmd `cmd:"" help:"load manifest from file"`
Save SaveCmd `cmd:"" help:"save manifest to file"`
Import ImportCmd `cmd:"" help:"import directory objects"`
Export ExportCmd `cmd:"" help:"export directory objects"`
Backup BackupCmd `cmd:"" help:"backup directory data"`
Restore RestoreCmd `cmd:"" help:"restore directory data"`
Test TestCmd `cmd:"" help:"execute assertions"`
Install InstallCmd `cmd:"" help:"install topaz container"`
Configure ConfigureCmd `cmd:"" help:"configure topaz service"`
Update UpdateCmd `cmd:"" help:"update topaz container version"`
Uninstall UninstallCmd `cmd:"" help:"uninstall topaz container"`
Version VersionCmd `cmd:"" help:"version information"`
NoCheck bool `name:"no-check" env:"TOPAZ_NO_CHECK" help:"disable local container status check"`
}
type VersionCmd struct{}
func (cmd *VersionCmd) Run(c *cc.CommonCtx) error {
fmt.Fprintf(c.UI.Output(), "%s - %s (%s)\n",
x.AppName,
version.GetInfo().String(),
x.AppVersionTag,
)
return nil
}
func CheckRunning(c *cc.CommonCtx) error {
if c.NoCheck {
return nil
}
if running, err := dockerx.IsRunning(dockerx.Topaz); !running || err != nil {
if !running {
return ErrNotRunning
}
if err != nil {
return err
}
}
return nil
}