mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
4d30d3a7e1
* fix(cli): typo in clis * chore: fix typos in guides and readme * markdown lint * readme typos * markdown lint * typos in security.md * login de * login en * console de * console en * Apply suggestions from code review E-Mail instead of Email Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: Florian Forster <florian@caos.ch>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
_ "embed"
|
|
"errors"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/cmd/admin"
|
|
)
|
|
|
|
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",
|
|
Short: "The ZITADEL CLI lets you interact with ZITADEL",
|
|
Long: `The ZITADEL CLI lets you interact with ZITADEL`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return errors.New("no additional command provided")
|
|
},
|
|
}
|
|
|
|
viper.AutomaticEnv()
|
|
viper.SetEnvPrefix("ZITADEL")
|
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
|
viper.SetConfigType("yaml")
|
|
err := viper.ReadConfig(bytes.NewBuffer(defaultConfig))
|
|
logging.OnError(err).Fatal("unable to read default config")
|
|
|
|
cobra.OnInitialize(initConfig)
|
|
cmd.PersistentFlags().StringArrayVar(&configFiles, "config", nil, "path to config file to overwrite system defaults")
|
|
|
|
cmd.AddCommand(admin.New())
|
|
|
|
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")
|
|
}
|
|
}
|