836d0fe119
- Parsing `alter` statement to catch `change old_name new_name ...` statements - Auto deducing renamed columns - When suspecting renamed columns, requesting explicit `--approve-renamed-columns` or `--skip-renamed-columns` - updated tests
51 lines
880 B
Go
51 lines
880 B
Go
/*
|
|
Copyright 2016 GitHub Inc.
|
|
See https://github.com/github/gh-ost/blob/master/LICENSE
|
|
*/
|
|
|
|
package base
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"regexp"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
prettifyDurationRegexp = regexp.MustCompile("([.][0-9]+)")
|
|
)
|
|
|
|
func PrettifyDurationOutput(d time.Duration) string {
|
|
if d < time.Second {
|
|
return "0s"
|
|
}
|
|
result := fmt.Sprintf("%s", d)
|
|
result = prettifyDurationRegexp.ReplaceAllString(result, "")
|
|
return result
|
|
}
|
|
|
|
func FileExists(fileName string) bool {
|
|
if _, err := os.Stat(fileName); err == nil {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func StringContainsAll(s string, substrings ...string) bool {
|
|
nonEmptyStringsFound := false
|
|
for _, substring := range substrings {
|
|
if s == "" {
|
|
continue
|
|
}
|
|
if strings.Contains(s, substring) {
|
|
nonEmptyStringsFound = true
|
|
} else {
|
|
// Immediate failure
|
|
return false
|
|
}
|
|
}
|
|
return nonEmptyStringsFound
|
|
}
|