export_config.go 549 B

1234567891011121314151617181920212223242526272829
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/spf13/viper"
  5. "github.com/spf13/cobra"
  6. "gopkg.in/yaml.v2"
  7. )
  8. var cmdExportConfig = &cobra.Command{
  9. Use: "config",
  10. Short: "Export the server configuration",
  11. Long: "Export the whole configuration as Kurzd sees it",
  12. Run: exportConfigHandler,
  13. }
  14. func init() {
  15. cmdExport.AddCommand(cmdExportConfig)
  16. }
  17. func exportConfigHandler(cmd *cobra.Command, args []string) {
  18. settings := viper.AllSettings()
  19. y, err := yaml.Marshal(&settings)
  20. if err != nil {
  21. panic(err.Error())
  22. }
  23. fmt.Println(string(y))
  24. }