-
Notifications
You must be signed in to change notification settings - Fork 25
/
use.go
41 lines (32 loc) · 1011 Bytes
/
use.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
package configure
import (
"fmt"
"os"
"path/filepath"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/aserto-dev/topaz/pkg/cli/cmd/common"
)
type UseConfigCmd struct {
Name ConfigName `arg:"" required:"" help:"topaz config name"`
ConfigDir string `flag:"" required:"false" default:"${topaz_cfg_dir}" help:"path to config folder" `
}
func (cmd *UseConfigCmd) Run(c *cc.CommonCtx) error {
if _, err := os.Stat(filepath.Join(cmd.ConfigDir, fmt.Sprintf("%s.yaml", cmd.Name))); err != nil {
return err
}
topazContainers, err := c.GetRunningContainers()
if err != nil {
return err
}
if len(topazContainers) > 0 {
return cc.ErrIsRunning
}
c.Config.Active.Config = cmd.Name.String()
c.Config.Active.ConfigFile = filepath.Join(cmd.ConfigDir, fmt.Sprintf("%s.yaml", cmd.Name))
c.UI.Normal().Msgf("Using configuration %q", cmd.Name)
if err := c.SaveContextConfig(common.CLIConfigurationFile); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
return nil
}