From c7e36f9aba85493c19c00e84b5f1e87477a2f155 Mon Sep 17 00:00:00 2001 From: Patrik Cyvoct Date: Wed, 8 Apr 2020 08:34:57 +0200 Subject: [PATCH] feat(core): add standard success message templates Signed-off-by: Patrik Cyvoct --- internal/core/result.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/core/result.go b/internal/core/result.go index 54d817e7c5..05c1eaa540 100644 --- a/internal/core/result.go +++ b/internal/core/result.go @@ -2,6 +2,7 @@ package core import ( "encoding/json" + "fmt" "strings" "github.com/fatih/color" @@ -10,8 +11,14 @@ import ( ) type SuccessResult struct { - Message string - Details string + Message string + Details string + Resource string + Verb string +} + +var standardSuccessMessages = map[string]string{ + "delete": "%s has been successfully deleted.", } func (s *SuccessResult) MarshalHuman() (string, error) { @@ -45,5 +52,10 @@ func (s *SuccessResult) getMessage() string { if s.Message != "" { return s.Message } + + if messageTemplate, exists := standardSuccessMessages[s.Verb]; exists && s.Resource != "" { + return fmt.Sprintf(messageTemplate, s.Resource) + } + return "Success" }