mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Improve the comments in utils.go
This commit is contained in:
parent
0a2addb532
commit
4863901859
15
wtf/utils.go
15
wtf/utils.go
@ -38,6 +38,7 @@ func CenterText(str string, width int) string {
|
|||||||
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))
|
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecuteCommand executes an external command on the local machine as the current user
|
||||||
func ExecuteCommand(cmd *exec.Cmd) string {
|
func ExecuteCommand(cmd *exec.Cmd) string {
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -78,12 +79,20 @@ func Exclude(strs []string, val string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindMatch takes a regex pattern and a string of data and returns back all the matches
|
||||||
|
// in that string
|
||||||
func FindMatch(pattern string, data string) [][]string {
|
func FindMatch(pattern string, data string) [][]string {
|
||||||
r := regexp.MustCompile(pattern)
|
r := regexp.MustCompile(pattern)
|
||||||
return r.FindAllStringSubmatch(data, -1)
|
return r.FindAllStringSubmatch(data, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NameFromEmail takes an email address and returns the part that comes before the @ symbol
|
// NameFromEmail takes an email address and returns the part that comes before the @ symbol
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// NameFromEmail("test_user@example.com")
|
||||||
|
// > "Test_user"
|
||||||
|
//
|
||||||
func NameFromEmail(email string) string {
|
func NameFromEmail(email string) string {
|
||||||
parts := strings.Split(email, "@")
|
parts := strings.Split(email, "@")
|
||||||
return strings.Title(strings.Replace(parts[0], ".", " ", -1))
|
return strings.Title(strings.Replace(parts[0], ".", " ", -1))
|
||||||
@ -91,6 +100,12 @@ func NameFromEmail(email string) string {
|
|||||||
|
|
||||||
// NamesFromEmails takes a slice of email addresses and returns a slice of the parts that
|
// NamesFromEmails takes a slice of email addresses and returns a slice of the parts that
|
||||||
// come before the @ symbol
|
// come before the @ symbol
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// NamesFromEmail("test_user@example.com", "other_user@example.com")
|
||||||
|
// > []string{"Test_user", "Other_user"}
|
||||||
|
//
|
||||||
func NamesFromEmails(emails []string) []string {
|
func NamesFromEmails(emails []string) []string {
|
||||||
names := []string{}
|
names := []string{}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user