MCPcopy Create free account
hub / github.com/algolia/cli / GetSuccessMessage

Function GetSuccessMessage

pkg/cmd/synonyms/save/messages.go:23–86  ·  view source on GitHub ↗
(flags shared.SynonymFlags, index string)

Source from the content-addressed store, hash-verified

21const successTemplate = `{{ .Type }} '{{ .ID }}' successfully saved with {{ .Values }} to {{ .Index }}`
22
23func GetSuccessMessage(flags shared.SynonymFlags, index string) (string, error) {
24 var successMessage SuccessMessage
25
26 if flags.SynonymType == "" || flags.SynonymType == shared.Regular {
27 successMessage = SuccessMessage{
28 Type: "Synonym",
29 ID: flags.SynonymID,
30 Values: fmt.Sprintf("%s (%s)",
31 utils.Pluralize(len(flags.Synonyms), "synonym"),
32 strings.Join(flags.Synonyms, ", ")),
33 Index: index,
34 }
35 }
36
37 switch flags.SynonymType {
38 case shared.OneWay, shared.AltOneWay:
39 successMessage = SuccessMessage{
40 Type: "One way synonym",
41 ID: flags.SynonymID,
42 Values: fmt.Sprintf("input '%s' and %s (%s)",
43 flags.SynonymInput,
44 utils.Pluralize(len(flags.Synonyms), "synonym"),
45 strings.Join(flags.Synonyms, ", ")),
46 Index: index,
47 }
48 case shared.Placeholder:
49 successMessage = SuccessMessage{
50 Type: "Placeholder synonym",
51 ID: flags.SynonymID,
52 Values: fmt.Sprintf("placeholder '%s' and %s (%s)",
53 flags.SynonymPlaceholder,
54 utils.Pluralize(len(flags.SynonymReplacements), "replacement"),
55 strings.Join(flags.SynonymReplacements, ", ")),
56 Index: index,
57 }
58 case shared.AltCorrection1,
59 shared.AltCorrection2,
60 shared.AltAltCorrection1,
61 shared.AltAltCorrection2:
62 altCorrectionType := "1"
63 if flags.SynonymType == shared.AltCorrection2 ||
64 flags.SynonymType == shared.AltAltCorrection2 {
65 altCorrectionType = "2"
66 }
67 altCorrectionType = "Alt correction " + altCorrectionType + " synonym"
68 successMessage = SuccessMessage{
69 Type: altCorrectionType,
70 ID: flags.SynonymID,
71 Values: fmt.Sprintf("word '%s' and %s (%s)",
72 flags.SynonymWord,
73 utils.Pluralize(len(flags.SynonymCorrections), "correction"),
74 strings.Join(flags.SynonymCorrections, ", ")),
75 Index: index,
76 }
77 }
78
79 t := template.Must(template.New("successMessage").Parse(successTemplate))
80

Callers 2

NewSaveCmdFunction · 0.85

Calls 2

PluralizeFunction · 0.92
StringMethod · 0.45

Tested by 1