summaryrefslogtreecommitdiffstats
path: root/pkg/utils/utils.go
diff options
context:
space:
mode:
authorAndrei Miulescu <lusu777@gmail.com>2018-08-12 19:31:27 +1000
committerAndrei Miulescu <lusu777@gmail.com>2018-08-12 19:31:27 +1000
commitdcd461d29f21a9626d5298a03283b6d8b46312c3 (patch)
tree42f43f27eb7403c60cc05805fc627debff76417b /pkg/utils/utils.go
parent98c22a36fdaf8806f8fafe8f1e23e53f8e97658d (diff)
Restrucure project in a way where it is more modular
Diffstat (limited to 'pkg/utils/utils.go')
-rw-r--r--pkg/utils/utils.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
new file mode 100644
index 000000000..01556ea4f
--- /dev/null
+++ b/pkg/utils/utils.go
@@ -0,0 +1,49 @@
+package utils
+
+import (
+ "fmt"
+ "log"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "github.com/fatih/color"
+)
+
+func splitLines(multilineString string) []string {
+ multilineString = strings.Replace(multilineString, "\r", "", -1)
+ if multilineString == "" || multilineString == "\n" {
+ return make([]string, 0)
+ }
+ lines := strings.Split(multilineString, "\n")
+ if lines[len(lines)-1] == "" {
+ return lines[:len(lines)-1]
+ }
+ return lines
+}
+
+func withPadding(str string, padding int) string {
+ if padding-len(str) < 0 {
+ return str
+ }
+ return str + strings.Repeat(" ", padding-len(str))
+}
+
+func coloredString(str string, colorAttribute color.Attribute) string {
+ colour := color.New(colorAttribute)
+ return coloredStringDirect(str, colour)
+}
+
+// used for aggregating a few color attributes rather than just sending a single one
+func coloredStringDirect(str string, colour *color.Color) string {
+ return colour.SprintFunc()(fmt.Sprint(str))
+}
+
+// used to get the project name
+func getCurrentProject() string {
+ pwd, err := os.Getwd()
+ if err != nil {
+ log.Fatalln(err.Error())
+ }
+ return filepath.Base(pwd)
+}