List source and database drivers in help text

This commit is contained in:
Dale Hui 2018-06-12 16:17:52 +08:00
parent 0d9f636356
commit c4e855b58c
3 changed files with 27 additions and 1 deletions

View File

@ -11,6 +11,8 @@ import (
"time"
"github.com/golang-migrate/migrate"
"github.com/golang-migrate/migrate/database"
"github.com/golang-migrate/migrate/source"
)
// set main log
@ -52,7 +54,9 @@ Commands:
drop Drop everyting inside database
force V Set version V but don't run migration (ignores dirty state)
version Print current migration version
`)
Source drivers: `+strings.Join(source.List(), ", ")+`
Database drivers: `+strings.Join(database.List(), ", ")+"\n")
}
flag.Parse()

View File

@ -110,3 +110,14 @@ func Register(name string, driver Driver) {
}
drivers[name] = driver
}
// List lists the registered drivers
func List() []string {
driversMu.RLock()
defer driversMu.RUnlock()
names := make([]string, 0, len(drivers))
for n := range drivers {
names = append(names, n)
}
return names
}

View File

@ -105,3 +105,14 @@ func Register(name string, driver Driver) {
}
drivers[name] = driver
}
// List lists the registered drivers
func List() []string {
driversMu.RLock()
defer driversMu.RUnlock()
names := make([]string, 0, len(drivers))
for n := range drivers {
names = append(names, n)
}
return names
}