package cmd
import (
"fmt"
"os"
"strings"
conf "github.com/goodrain/rainbond/cmd/grctl/option"
"github.com/goodrain/rainbond/grctl/clients"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
func GetCmds() []cli.Command {
cmds := []cli.Command{}
cmds = append(cmds, NewSourceBuildCmd())
cmds = append(cmds, NewCmdConfig())
cmds = append(cmds, NewCmdRegistry())
cmds = append(cmds, NewCmdReplace())
cmds = append(cmds, NewCmdMigrateConsole())
cmds = append(cmds, NewCmdGPUShare())
return cmds
}
func Common(c *cli.Context) {
config, err := conf.LoadConfig(c)
if err != nil {
logrus.Warn("Load config file error.", err.Error())
}
kc := c.GlobalString("kubeconfig")
if kc != "" {
config.Kubernets.KubeConf = kc
}
if err := clients.InitClient(config.Kubernets.KubeConf); err != nil {
logrus.Errorf("error config k8s,details %s", err.Error())
}
}
func CommonWithoutRegion(c *cli.Context) {
config, err := conf.LoadConfig(c)
if err != nil {
logrus.Warn("Load config file error.", err.Error())
}
kc := c.GlobalString("kubeconfig")
if kc != "" {
config.Kubernets.KubeConf = kc
}
if err := clients.InitClient(config.Kubernets.KubeConf); err != nil {
logrus.Errorf("error config k8s,details %s", err.Error())
}
}
func fatal(msg string, code int) {
if len(msg) > 0 {
if !strings.HasSuffix(msg, "\n") {
msg += "\n"
}
fmt.Fprint(os.Stderr, msg)
}
os.Exit(code)
}
func GetTenantNamePath() string {
tenantnamepath, err := conf.GetTenantNamePath()
if err != nil {
logrus.Warn("Ger Home error", err.Error())
return tenantnamepath
}
return tenantnamepath
}