-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
55 lines (46 loc) · 1.08 KB
/
util.go
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
package utils
import (
"fmt"
"io"
"os/exec"
"strings"
"github.com/cocoup/go-smart/tools/gocli/cmd/api/spec"
)
func GetGitName() string {
cmd := exec.Command("git", "config", "user.name")
out, err := cmd.CombinedOutput()
if err != nil {
return ""
}
return strings.TrimSpace(string(out))
}
func GetGitEmail() string {
cmd := exec.Command("git", "config", "user.email")
out, err := cmd.CombinedOutput()
if err != nil {
return ""
}
return strings.TrimSpace(string(out))
}
// ComponentName returns component name for typescript
func ComponentName(api *spec.ApiSpec) string {
name := api.Service.Name
if strings.HasSuffix(name, "-api") {
return name[:len(name)-4] + "Components"
}
return name + "Components"
}
// WriteIndent writes tab spaces
func WriteIndent(writer io.Writer, indent int) {
for i := 0; i < indent; i++ {
fmt.Fprint(writer, "\t")
}
}
// RemoveComment filters comment content
func RemoveComment(line string) string {
commentIdx := strings.Index(line, "//")
if commentIdx >= 0 {
return strings.TrimSpace(line[:commentIdx])
}
return strings.TrimSpace(line)
}