mirror of https://github.com/pressly/goose.git
Add NO_COLOR (-no-color) support (#409)
parent
b6c15b9660
commit
5a6c34ee2d
|
@ -5,4 +5,7 @@
|
|||
*.test
|
||||
|
||||
# Files output by tests
|
||||
/bin
|
||||
/bin
|
||||
|
||||
# Local testing
|
||||
.envrc
|
||||
|
|
9
Makefile
9
Makefile
|
@ -24,3 +24,12 @@ test-clickhouse:
|
|||
|
||||
docker-cleanup:
|
||||
docker stop -t=0 $$(docker ps --filter="label=goose_test" -aq)
|
||||
|
||||
start-postgres:
|
||||
docker run --rm -d \
|
||||
-e POSTGRES_USER=${GOOSE_POSTGRES_DB_USER} \
|
||||
-e POSTGRES_PASSWORD=${GOOSE_POSTGRES_PASSWORD} \
|
||||
-e POSTGRES_DB=${GOOSE_POSTGRES_DBNAME} \
|
||||
-p ${GOOSE_POSTGRES_PORT}:5432 \
|
||||
-l goose_test \
|
||||
postgres:14-alpine
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"text/template"
|
||||
|
||||
"github.com/pressly/goose/v3"
|
||||
|
@ -26,6 +27,7 @@ var (
|
|||
sslcert = flags.String("ssl-cert", "", "file path to SSL certificates in pem format (only support on mysql)")
|
||||
sslkey = flags.String("ssl-key", "", "file path to SSL key in pem format (only support on mysql)")
|
||||
noVersioning = flags.Bool("no-versioning", false, "apply migration commands with no versioning, in file order, from directory pointed to")
|
||||
noColor = flags.Bool("no-color", false, "disable color output (NO_COLOR env variable supported)")
|
||||
)
|
||||
var (
|
||||
gooseVersion = ""
|
||||
|
@ -116,8 +118,10 @@ func main() {
|
|||
if len(args) > 3 {
|
||||
arguments = append(arguments, args[3:]...)
|
||||
}
|
||||
|
||||
options := []goose.OptionsFunc{}
|
||||
if *noColor || checkNoColorFromEnv() {
|
||||
options = append(options, goose.WithNoColor(true))
|
||||
}
|
||||
if *allowMissing {
|
||||
options = append(options, goose.WithAllowMissing())
|
||||
}
|
||||
|
@ -135,10 +139,20 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func checkNoColorFromEnv() bool {
|
||||
if s := os.Getenv(envNoColor); s != "" {
|
||||
ok, _ := strconv.ParseBool(s)
|
||||
return ok
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
envGooseDriver = "GOOSE_DRIVER"
|
||||
envGooseDBString = "GOOSE_DBSTRING"
|
||||
envGooseMigrationDir = "GOOSE_MIGRATION_DIR"
|
||||
// https://no-color.org/
|
||||
envNoColor = "NO_COLOR"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
1
goose.go
1
goose.go
|
@ -15,6 +15,7 @@ var (
|
|||
maxVersion = int64((1 << 63) - 1)
|
||||
timestampFormat = "20060102150405"
|
||||
verbose = false
|
||||
noColor = false
|
||||
|
||||
// base fs to lookup migrations
|
||||
baseFS fs.FS = osFS{}
|
||||
|
|
|
@ -113,7 +113,11 @@ const (
|
|||
|
||||
func verboseInfo(s string, args ...interface{}) {
|
||||
if verbose {
|
||||
log.Printf(grayColor+s+resetColor, args...)
|
||||
if noColor {
|
||||
log.Printf(s, args...)
|
||||
} else {
|
||||
log.Printf(grayColor+s+resetColor, args...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue