mirror of https://github.com/pressly/goose.git
Add NO_COLOR (-no-color) support (#409)
parent
b6c15b9660
commit
5a6c34ee2d
|
@ -5,4 +5,7 @@
|
||||||
*.test
|
*.test
|
||||||
|
|
||||||
# Files output by tests
|
# Files output by tests
|
||||||
/bin
|
/bin
|
||||||
|
|
||||||
|
# Local testing
|
||||||
|
.envrc
|
||||||
|
|
9
Makefile
9
Makefile
|
@ -24,3 +24,12 @@ test-clickhouse:
|
||||||
|
|
||||||
docker-cleanup:
|
docker-cleanup:
|
||||||
docker stop -t=0 $$(docker ps --filter="label=goose_test" -aq)
|
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"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"strconv"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/pressly/goose/v3"
|
"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)")
|
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)")
|
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")
|
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 (
|
var (
|
||||||
gooseVersion = ""
|
gooseVersion = ""
|
||||||
|
@ -116,8 +118,10 @@ func main() {
|
||||||
if len(args) > 3 {
|
if len(args) > 3 {
|
||||||
arguments = append(arguments, args[3:]...)
|
arguments = append(arguments, args[3:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
options := []goose.OptionsFunc{}
|
options := []goose.OptionsFunc{}
|
||||||
|
if *noColor || checkNoColorFromEnv() {
|
||||||
|
options = append(options, goose.WithNoColor(true))
|
||||||
|
}
|
||||||
if *allowMissing {
|
if *allowMissing {
|
||||||
options = append(options, goose.WithAllowMissing())
|
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 (
|
const (
|
||||||
envGooseDriver = "GOOSE_DRIVER"
|
envGooseDriver = "GOOSE_DRIVER"
|
||||||
envGooseDBString = "GOOSE_DBSTRING"
|
envGooseDBString = "GOOSE_DBSTRING"
|
||||||
envGooseMigrationDir = "GOOSE_MIGRATION_DIR"
|
envGooseMigrationDir = "GOOSE_MIGRATION_DIR"
|
||||||
|
// https://no-color.org/
|
||||||
|
envNoColor = "NO_COLOR"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
1
goose.go
1
goose.go
|
@ -15,6 +15,7 @@ var (
|
||||||
maxVersion = int64((1 << 63) - 1)
|
maxVersion = int64((1 << 63) - 1)
|
||||||
timestampFormat = "20060102150405"
|
timestampFormat = "20060102150405"
|
||||||
verbose = false
|
verbose = false
|
||||||
|
noColor = false
|
||||||
|
|
||||||
// base fs to lookup migrations
|
// base fs to lookup migrations
|
||||||
baseFS fs.FS = osFS{}
|
baseFS fs.FS = osFS{}
|
||||||
|
|
|
@ -113,7 +113,11 @@ const (
|
||||||
|
|
||||||
func verboseInfo(s string, args ...interface{}) {
|
func verboseInfo(s string, args ...interface{}) {
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf(grayColor+s+resetColor, args...)
|
if noColor {
|
||||||
|
log.Printf(s, args...)
|
||||||
|
} else {
|
||||||
|
log.Printf(grayColor+s+resetColor, args...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
up.go
4
up.go
|
@ -24,6 +24,10 @@ func WithNoVersioning() OptionsFunc {
|
||||||
return func(o *options) { o.noVersioning = true }
|
return func(o *options) { o.noVersioning = true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithNoColor(b bool) OptionsFunc {
|
||||||
|
return func(o *options) { noColor = b }
|
||||||
|
}
|
||||||
|
|
||||||
func withApplyUpByOne() OptionsFunc {
|
func withApplyUpByOne() OptionsFunc {
|
||||||
return func(o *options) { o.applyUpByOne = true }
|
return func(o *options) { o.applyUpByOne = true }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue