From b314912821c6e0abf47e55358824beb986d3caa2 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sat, 17 Apr 2021 12:02:00 +0200 Subject: [PATCH] describe backends --- cmd/info.go | 2 -- internal/colors/colors.go | 7 +++++++ internal/config.go | 44 +++++++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/cmd/info.go b/cmd/info.go index 6b279c4..ca1a47c 100644 --- a/cmd/info.go +++ b/cmd/info.go @@ -24,8 +24,6 @@ var infoCmd = &cobra.Command{ Use: "info", Short: "Show info about the config", Run: func(cmd *cobra.Command, args []string) { - CheckErr(internal.CheckConfig()) - internal.GetConfig().Describe() }, } diff --git a/internal/colors/colors.go b/internal/colors/colors.go index c27f8fc..a79d3fb 100644 --- a/internal/colors/colors.go +++ b/internal/colors/colors.go @@ -2,6 +2,7 @@ package colors import ( "fmt" + "strings" "github.com/fatih/color" ) @@ -20,3 +21,9 @@ func PrimaryPrint(msg string, args ...interface{}) { func DisableColors(state bool) { color.NoColor = state } + +func PrintDescription(left string, right string) { + right = strings.Trim(right, "\n") + right = strings.Trim(right, "\t") + Body.Printf("%s\t%s\n", Secondary.Sprint(left), right) +} diff --git a/internal/config.go b/internal/config.go index 0ee7520..77611e4 100644 --- a/internal/config.go +++ b/internal/config.go @@ -54,56 +54,68 @@ func GetPathRelativeToConfig(p string) (string, error) { } } -func PrintDescription(left string, right string) { - colors.Body.Printf("%s\t%s\n", colors.Secondary.Sprint(left), strings.TrimPrefix(right, "\t")) -} - func (c *Config) Describe() { + // Locations for name, l := range c.Locations { var tmp string colors.PrimaryPrint(`Location: "%s"`, name) - PrintDescription("From", l.From) + colors.PrintDescription("From", l.From) tmp = "" for _, to := range l.To { - tmp += fmt.Sprintf("\t→ %s\n", to) + tmp += fmt.Sprintf("\t%s %s\n", colors.Success.Sprint("→"), to) } - PrintDescription("To", tmp) + colors.PrintDescription("To", tmp) if l.Cron != "" { - PrintDescription("Cron", l.Cron) + colors.PrintDescription("Cron", l.Cron) } after, before := len(l.Hooks.After), len(l.Hooks.Before) if after+before > 0 { tmp = "" if before > 0 { - tmp += "\tBefore\n" + tmp += "\tBefore" for _, cmd := range l.Hooks.Before { - tmp += colors.Faint.Sprintf("\t ▶ %s\n", cmd) + tmp += colors.Faint.Sprintf("\n\t ▶ %s", cmd) } } if after > 0 { - tmp += "\tAfter\n" + tmp += "\n\tAfter" for _, cmd := range l.Hooks.After { - tmp += colors.Faint.Sprintf("\t ▶ %s\n", cmd) + tmp += colors.Faint.Sprintf("\n\t ▶ %s", cmd) } } - PrintDescription("Hooks", tmp) + colors.PrintDescription("Hooks", tmp) } if len(l.Options) > 0 { tmp = "" for t, options := range l.Options { - tmp += "\t" + t + "\n" + tmp += "\n\t" + t for option, values := range options { for _, value := range values { - tmp += colors.Faint.Sprintf("\t✧ --%s=%s\n", option, value) + tmp += colors.Faint.Sprintf("\n\t ✧ --%s=%s", option, value) } } } - PrintDescription("Options", tmp) + colors.PrintDescription("Options", tmp) + } + } + + // Backends + for name, b := range c.Backends { + colors.PrimaryPrint("Backend: \"%s\"", name) + colors.PrintDescription("Type", b.Type) + colors.PrintDescription("Path", b.Path) + + if len(b.Env) > 0 { + tmp := "" + for option, value := range b.Env { + tmp += fmt.Sprintf("\n\t%s %s %s", colors.Success.Sprint("✧"), option, colors.Faint.Sprint(value)) + } + colors.PrintDescription("Env", tmp) } } }