-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon_utils.go
More file actions
58 lines (49 loc) · 1.16 KB
/
Copy pathcommon_utils.go
File metadata and controls
58 lines (49 loc) · 1.16 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package utils
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"reflect"
"runtime/debug"
"strings"
)
// getType returns the type of a given value as a string
func GetType(value interface{}) string {
return reflect.TypeOf(value).String()
}
func GetParamValue(parameterName string, parameterValue interface{}) interface{} {
if parameterValue != nil {
return parameterValue
} else {
fmt.Printf("Parameter '%s' value not found.\n", parameterName)
return nil
}
}
func GetCurrentPath() string {
executablePath, err := os.Executable()
if err != nil {
// Handle the error if necessary
return ""
}
return filepath.Dir(executablePath)
}
func GetCurrentBranch() (string, error) {
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
output, err := cmd.Output()
if err != nil {
return "", err
}
// Remove leading/trailing whitespaces and newline characters
branch := strings.TrimSpace(string(output))
return branch, nil
}
// Function to clear the console screen
func ClearScreen() {
fmt.Print("\033[H\033[2J")
}
func LogErrorWithTraceBack(message string, err error) {
if err != nil {
fmt.Printf("%s: %v\n%s", message, err, debug.Stack())
}
}