2023-06-12 22:40:22 -04:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2023-06-17 14:17:02 -04:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2023-06-12 22:40:22 -04:00
|
|
|
)
|
|
|
|
|
2023-06-17 14:17:02 -04:00
|
|
|
func PrintHeader() {
|
2023-06-17 14:27:49 -04:00
|
|
|
fmt.Println(CreateLine(15))
|
2023-06-17 14:17:02 -04:00
|
|
|
fmt.Println(" __ __ __ ______ __ ")
|
|
|
|
fmt.Println(" / //_/ ____ ____/ / ___ / ____/ _____ ___ ____ _ / /_ ____ _____")
|
|
|
|
fmt.Println(" / ,< / __ \\ / __ / / _ \\ ______ / / / ___/ / _ \\ / __ `/ / __/ / __ \\ / ___/")
|
|
|
|
fmt.Println(" / /| | / /_/ // /_/ / / __//_____// /___ / / / __// /_/ / / /_ / /_/ / / / ")
|
|
|
|
fmt.Println("/_/ |_| \\____/ \\__,_/ \\___/ \\____/ /_/ \\___/ \\__,_/ \\__/ \\____/ /_/ ")
|
|
|
|
fmt.Println("")
|
2023-06-17 14:27:49 -04:00
|
|
|
fmt.Println(CreateLine(15))
|
2023-06-17 14:17:02 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateLine(weight int) string {
|
|
|
|
var line string
|
|
|
|
for i := 0; i < weight; i++ {
|
|
|
|
line += "--- "
|
|
|
|
}
|
|
|
|
return line
|
|
|
|
}
|
|
|
|
|
|
|
|
func PrintHelpFormated(version string, author string, buildDate string, cmd *cobra.Command) {
|
|
|
|
|
|
|
|
fmt.Println("")
|
|
|
|
cmd.Help()
|
|
|
|
fmt.Println("")
|
|
|
|
fmt.Println(CreateLine(15))
|
|
|
|
fmt.Println("| Version: " + version + " || Author: " + author + " || Build date: " + buildDate + " |")
|
|
|
|
fmt.Println(CreateLine(15))
|
|
|
|
fmt.Println("")
|
|
|
|
}
|
|
|
|
|
2023-06-12 22:40:22 -04:00
|
|
|
func BytesToStrings(bytes []byte) []string {
|
|
|
|
var strings []string
|
|
|
|
for _, b := range bytes {
|
|
|
|
strings = append(strings, string(b))
|
|
|
|
}
|
|
|
|
return strings
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetGitToken() string {
|
|
|
|
token := os.Getenv("GIT_TOKEN")
|
|
|
|
return token
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsValidToken(token string) bool {
|
|
|
|
if len(token) != 40 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if token contains only hexadecimal characters (0-9 and a-f)
|
|
|
|
for _, c := range token {
|
|
|
|
if !(('0' <= c && c <= '9') || ('a' <= c && c <= 'f')) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsValidOrg(org string) bool {
|
|
|
|
// Check if organization is valid
|
|
|
|
// ...
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsValidProjectName(name string) bool {
|
|
|
|
// Check if project name is valid
|
|
|
|
// ...
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// function that print error message and exit program with specific error code
|
|
|
|
func ExitWithError(code int, msg string) {
|
|
|
|
// Print error message
|
|
|
|
fmt.Println(msg)
|
|
|
|
// Exit program with specific error code
|
|
|
|
os.Exit(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateDir(dirName string) {
|
|
|
|
path, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Current working directory: ", path)
|
2023-06-17 14:17:02 -04:00
|
|
|
fmt.Println("Directory to create: ", dirName)
|
2023-06-12 22:40:22 -04:00
|
|
|
|
|
|
|
dirPath := filepath.Join(path, dirName)
|
|
|
|
|
|
|
|
err = os.Mkdir(dirPath, 0755)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Created directory '%s' \n", dirName)
|
|
|
|
}
|
2023-06-17 14:17:02 -04:00
|
|
|
|
|
|
|
func PadString(s string, n int) string {
|
|
|
|
if len(s) >= n {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
return s + strings.Repeat(" ", n-len(s))
|
|
|
|
}
|