mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
40 lines
746 B
Go
40 lines
746 B
Go
package util
|
|
|
|
import (
|
|
"net/url"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func HomeDir() string {
|
|
if h := os.Getenv("HOME"); h != "" {
|
|
return h
|
|
}
|
|
return os.Getenv("USERPROFILE") // windows
|
|
}
|
|
|
|
func IsURL(str string) bool {
|
|
parsed, err := url.ParseRequestURI(str)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
return parsed.Scheme != ""
|
|
}
|
|
|
|
func AppName(name string) string {
|
|
words := strings.Split(strings.Title(strings.Replace(name, "-", " ", -1)), " ")
|
|
casedWords := []string{}
|
|
for i, word := range words {
|
|
if strings.ToLower(word) == "ai" {
|
|
casedWords = append(casedWords, "AI")
|
|
} else if strings.ToLower(word) == "io" && i > 0 {
|
|
casedWords[i-1] += ".io"
|
|
} else {
|
|
casedWords = append(casedWords, word)
|
|
}
|
|
}
|
|
|
|
return strings.Join(casedWords, " ")
|
|
}
|