This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/config"
|
||||
"log/slog"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var configInitcmd = &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "create config",
|
||||
Long: "create config file with defaults",
|
||||
// Args: cobra.ExactArgs(2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
slog.Info("create config")
|
||||
config := config.CliConfig{
|
||||
Server: map[string]config.Server{
|
||||
"main": {
|
||||
Url: "https://kontor-gin.thpeetz.de",
|
||||
Username: "user",
|
||||
Password: "password",
|
||||
},
|
||||
"local": {
|
||||
Url: "http://localhost:8550",
|
||||
Username: "user",
|
||||
Password: "password",
|
||||
},
|
||||
},
|
||||
}
|
||||
viper.Set("server", config.Server)
|
||||
if err := viper.WriteConfig(); err != nil {
|
||||
slog.Info("write config failed", "error", err.Error())
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
configInitcmd.Flags().BoolVarP(&config.Overwrite, "overwrite", "y", false, "overwrite existing config")
|
||||
configCmd.AddCommand(configInitcmd)
|
||||
}
|
||||
Reference in New Issue
Block a user