-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.go
61 lines (50 loc) · 1.16 KB
/
helpers.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
56
57
58
59
60
61
package utils
import (
"fmt"
"os"
"strings"
"github.com/bin3xish477/csg/models"
"github.com/jedib0t/go-pretty/table"
"github.com/jedib0t/go-pretty/text"
)
func StringInSlice(str string, slice []string) bool {
var temp []string
for _, s := range slice {
temp = append(temp, strings.ToLower(s))
}
for _, s := range temp {
if s == str {
return true
}
}
return false
}
func FileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func PrintTable(c []*models.Credential) {
if len(c) == 0 {
fmt.Printf("[%snote%s] no credentials matched specified options...\n", Yellow, End)
return
}
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleLight)
t.Style().Format.Header = text.FormatTitle
t.AppendHeader(
table.Row{
fmt.Sprintf("%sID%s", Blue, End),
fmt.Sprintf("%sHost%s", Red, End),
fmt.Sprintf("%sApp%s", Yellow, End),
fmt.Sprintf("%sUser%s", Green, End),
fmt.Sprintf("%sPassword%s", Purple, End),
})
for _, cred := range c {
t.AppendRow([]interface{}{cred.ID, cred.Host, cred.App, cred.User, cred.Password})
}
t.Render()
}