Files
kontor/kontor-gin/internal/cmd/export.go
T
tpeetz bc88c694ee
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
add MediaLofi in kontor-gin (#97)
Co-authored-by: Thomas Peetz <thomas.peetz@cimt-ag.de>
Reviewed-on: #97
2026-10-09 16:26:11 +00:00

47 lines
1.3 KiB
Go

package cmd
import (
"fmt"
"kontor-api-gin/internal/api"
"kontor-api-gin/internal/config"
"log/slog"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"resty.dev/v3"
)
var filename string
var exportCmd = &cobra.Command{
Use: "export",
Short: "Export Kontor Database",
Long: "Export Kontor Database to given file",
// Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
slog.Info("export kontor")
slog.Info("Verbosity level", "level", config.Verbose)
slog.Info(fmt.Sprintf("Using server: %s", config.ServerName))
client := resty.New()
defer client.Close()
localServer := config.Config.Server[config.ServerName]
export, _ := api.GetData(localServer, config.Config.ApiVersion)
err := api.WriteJson(export, filename)
if err != nil {
slog.Info("WriteJon failed", "Error:", err)
}
slog.Info("export kontor finished")
},
}
func init() {
rootCmd.AddCommand(exportCmd)
exportCmd.PersistentFlags().StringVarP(&filename, "file", "f", "/home/tpeetz/.sync/media/data-gin.json", "Filename to store data")
viper.BindPFlag("file", exportCmd.PersistentFlags().Lookup("file"))
exportCmd.PersistentFlags().StringVarP(&config.Config.ApiVersion, "api", "a", "api/v1", "API Version")
viper.BindPFlag("api", exportCmd.PersistentFlags().Lookup("api"))
}