mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 17:27:31 +00:00
feat(cli): init cli (#3186)
* feat(cli): initilize cli * fix(config): allow multiple files * refactor(cli): constructor naming * go mod tidy * refactor: move code out of v2 package * chore: logging v0.1 * chore: remove old gitignore * fix func Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
50
cmd/zitadel.go
Normal file
50
cmd/zitadel.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"io"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/cmd/admin"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
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 let's you interact with ZITADEL",
|
||||
Long: `The ZITADEL CLI let's you interact with ZITADEL`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
logging.New().Info("hello world")
|
||||
},
|
||||
}
|
||||
|
||||
viper.AutomaticEnv()
|
||||
viper.SetConfigType("yaml")
|
||||
err := viper.ReadConfig(bytes.NewBuffer(defaultConfig))
|
||||
logging.New().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")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user