Skip to content

Commit 5372296

Browse files
authored
feat(core): add standard success message templates (#845)
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent 97df426 commit 5372296

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

internal/core/result.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package core
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"strings"
67

78
"github.com/fatih/color"
@@ -10,8 +11,14 @@ import (
1011
)
1112

1213
type SuccessResult struct {
13-
Message string
14-
Details string
14+
Message string
15+
Details string
16+
Resource string
17+
Verb string
18+
}
19+
20+
var standardSuccessMessages = map[string]string{
21+
"delete": "%s has been successfully deleted.",
1522
}
1623

1724
func (s *SuccessResult) MarshalHuman() (string, error) {
@@ -45,5 +52,10 @@ func (s *SuccessResult) getMessage() string {
4552
if s.Message != "" {
4653
return s.Message
4754
}
55+
56+
if messageTemplate, exists := standardSuccessMessages[s.Verb]; exists && s.Resource != "" {
57+
return fmt.Sprintf(messageTemplate, s.Resource)
58+
}
59+
4860
return "Success"
4961
}

0 commit comments

Comments
 (0)