keel/config
Kevin Franklin Kim 7537cbcc1a
style: fix typo
2023-09-11 11:52:26 +02:00
..
config.go feat: add config types 2023-09-08 17:34:52 +02:00
readme.go style: fix typo 2023-09-11 11:52:26 +02:00
remote.go feat: add mongo and refactor readme 2023-09-08 22:24:31 +02:00
watch.go feat: add helper and update viper 2022-06-11 13:16:11 +02:00

package config

import (
	"fmt"

	"github.com/foomo/keel/markdown"
)

func Readme() string {
	var configRows [][]string
	var remoteRows [][]string
	c := Config()
	md := &markdown.Markdown{}

	{
		keys := c.AllKeys()
		for _, key := range keys {
			var fallback interface{}
			if v, ok := defaults[key]; ok {
				fallback = v
			}
			configRows = append(configRows, []string{
				markdown.Code(key),
				markdown.Code(TypeOf(key)),
				"",
				markdown.Code(fmt.Sprintf("%v", fallback)),
			})
		}

		for _, key := range requiredKeys {
			configRows = append(configRows, []string{
				markdown.Code(key),
				markdown.Code(TypeOf(key)),
				markdown.Code("true"),
				"",
			})
		}
	}

	{
		for _, remote := range remotes {
			remoteRows = append(remoteRows, []string{
				markdown.Code(remote.provider),
				markdown.Code(remote.path),
			})
		}
	}

	if len(configRows) > 0 || len(remoteRows) > 0 {
		md.Println("### Config")
		md.Println("")
	}

	if len(configRows) > 0 {
		md.Println("List of all registered config variables with their defaults.")
		md.Println("")
		md.Table([]string{"Key", "Type", "Required", "Default"}, configRows)
		md.Println("")
	}

	if len(remoteRows) > 0 {
		md.Println("#### Remotes")
		md.Println("")
		md.Println("List of remote config providers that are being watched.")
		md.Println("")
		md.Table([]string{"Provider", "Path"}, remoteRows)
		md.Println("")
	}

	return md.String()
}