package main import ( "fmt" "github.com/spf13/viper" "github.com/spf13/cobra" "gopkg.in/yaml.v2" ) var cmdExportConfig = &cobra.Command{ Use: "config", Short: "Export the server configuration", Long: "Export the whole configuration as Kurzd sees it", Run: exportConfigHandler, } func init() { cmdExport.AddCommand(cmdExportConfig) } func exportConfigHandler(cmd *cobra.Command, args []string) { settings := viper.AllSettings() y, err := yaml.Marshal(&settings) if err != nil { panic(err.Error()) } fmt.Println(string(y)) }