-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity_check.go
More file actions
43 lines (36 loc) · 1.53 KB
/
entity_check.go
File metadata and controls
43 lines (36 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package utils
import (
"fmt"
"path/filepath"
"github.com/indaco/tempo/internal/logger"
"github.com/indaco/tempo/internal/templatefuncs/providers/textprovider"
)
// CheckEntityForNew ensures that an entity does not already exist before creating a new one.
func CheckEntityForNew(entityType, entityName, outputPath string, force bool, logr logger.LoggerInterface) {
// Select logging function and action message based on `force` flag
logFunc, action := logr.Warning, "Use '--force' to overwrite it. Any changes will be lost."
if force {
logFunc, action = logr.Info, "Overwriting due to '--force' flag."
}
// Determine the appropriate path format based on entity type
paths := map[string]string{
"component": filepath.Join(outputPath, entityName),
"variant": outputPath,
}
path, exists := paths[entityType]
if !exists {
path = outputPath
}
msg := fmt.Sprintf("%s '%s' already exists.\n %s\n", textprovider.TitleCase(entityType), entityName, action)
logFunc(msg).WithAttrs("path", path)
}
// CheckEntityForDefine ensures that an entity exists before defining it.
func CheckEntityForDefine(entityType, outputPath string, force bool, logr logger.LoggerInterface) {
// Select logging function and action message based on `force` flag
logFunc, action := logr.Warning, "Use '--force' to overwrite them. Any changes will be lost."
if force {
logFunc, action = logr.Info, "Overwriting due to '--force' flag."
}
msg := fmt.Sprintf("Templates for '%s' already exist.\n %s", entityType, action)
logFunc(msg).WithAttrs("path", outputPath)
}