2022-02-09 14:01:19 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
_ "embed"
|
2022-04-25 15:05:20 +00:00
|
|
|
"errors"
|
2022-02-09 14:01:19 +00:00
|
|
|
"io"
|
2022-02-14 16:22:30 +00:00
|
|
|
"strings"
|
2022-02-09 14:01:19 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/logging"
|
2022-02-14 16:22:30 +00:00
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/cmd/admin"
|
2022-11-10 11:24:00 +00:00
|
|
|
"github.com/zitadel/zitadel/cmd/build"
|
2022-06-27 10:32:34 +00:00
|
|
|
"github.com/zitadel/zitadel/cmd/initialise"
|
|
|
|
"github.com/zitadel/zitadel/cmd/key"
|
|
|
|
"github.com/zitadel/zitadel/cmd/setup"
|
|
|
|
"github.com/zitadel/zitadel/cmd/start"
|
2022-02-09 14:01:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
configFiles []string
|
|
|
|
|
|
|
|
//go:embed defaults.yaml
|
|
|
|
defaultConfig []byte
|
|
|
|
)
|
|
|
|
|
|
|
|
func New(out io.Writer, in io.Reader, args []string) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "zitadel",
|
2022-05-21 10:44:09 +00:00
|
|
|
Short: "The ZITADEL CLI lets you interact with ZITADEL",
|
|
|
|
Long: `The ZITADEL CLI lets you interact with ZITADEL`,
|
2022-04-25 15:05:20 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return errors.New("no additional command provided")
|
2022-02-09 14:01:19 +00:00
|
|
|
},
|
2022-11-10 11:24:00 +00:00
|
|
|
Version: build.Version(),
|
2022-02-09 14:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
viper.AutomaticEnv()
|
2022-02-14 16:22:30 +00:00
|
|
|
viper.SetEnvPrefix("ZITADEL")
|
|
|
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
2022-02-09 14:01:19 +00:00
|
|
|
viper.SetConfigType("yaml")
|
|
|
|
err := viper.ReadConfig(bytes.NewBuffer(defaultConfig))
|
2022-02-14 16:22:30 +00:00
|
|
|
logging.OnError(err).Fatal("unable to read default config")
|
2022-02-09 14:01:19 +00:00
|
|
|
|
|
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
cmd.PersistentFlags().StringArrayVar(&configFiles, "config", nil, "path to config file to overwrite system defaults")
|
|
|
|
|
2022-06-27 10:32:34 +00:00
|
|
|
cmd.AddCommand(
|
|
|
|
admin.New(), //is now deprecated, remove later on
|
|
|
|
initialise.New(),
|
|
|
|
setup.New(),
|
|
|
|
start.New(),
|
|
|
|
start.NewStartFromInit(),
|
2022-08-31 07:52:43 +00:00
|
|
|
start.NewStartFromSetup(),
|
2022-06-27 10:32:34 +00:00
|
|
|
key.New(),
|
|
|
|
)
|
2022-02-09 14:01:19 +00:00
|
|
|
|
2022-11-10 11:24:00 +00:00
|
|
|
cmd.InitDefaultVersionFlag()
|
|
|
|
|
2022-02-09 14:01:19 +00:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func initConfig() {
|
|
|
|
for _, file := range configFiles {
|
|
|
|
viper.SetConfigFile(file)
|
|
|
|
err := viper.MergeInConfig()
|
|
|
|
logging.WithFields("file", file).OnError(err).Warn("unable to read config file")
|
|
|
|
}
|
|
|
|
}
|