Files
kontor/kontor-gin/internal/cmd/export.go
T
Thomas Peetz 72c08f9731
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Gitea Actions Demo / build-and-test (push) Failing after 29m54s
add method to handlers
2026-10-26 22:41:15 +01:00

39 lines
893 B
Go

package cmd
import (
"fmt"
"kontor-api-gin/internal/api"
"kontor-api-gin/internal/config"
"log/slog"
"github.com/spf13/cobra"
"resty.dev/v3"
)
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, config.FileName)
if err != nil {
slog.Info("WriteJon failed", "Error:", err)
}
slog.Info("export kontor finished")
},
}
func init() {
rootCmd.AddCommand(exportCmd)
}