mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2026-02-02 09:25:07 +01:00
Add --exit-code and --quiet flags to status command (#124)
Extending the `dbmate status` command with the ability to set an exit code or quiet output, for use in scripts. Flag names were copied from `git diff` command.
This commit is contained in:
parent
256f92ad19
commit
9d2ec369d8
3 changed files with 44 additions and 11 deletions
|
|
@ -492,26 +492,33 @@ func checkMigrationsStatus(db *DB) ([]statusResult, error) {
|
|||
}
|
||||
|
||||
// Status shows the status of all migrations
|
||||
func (db *DB) Status() error {
|
||||
func (db *DB) Status(quiet bool) (int, error) {
|
||||
results, err := checkMigrationsStatus(db)
|
||||
if err != nil {
|
||||
return err
|
||||
return -1, err
|
||||
}
|
||||
|
||||
var totalApplied int
|
||||
var line string
|
||||
|
||||
for _, res := range results {
|
||||
if res.applied {
|
||||
fmt.Println("[X]", res.filename)
|
||||
line = fmt.Sprintf("[X] %s", res.filename)
|
||||
totalApplied++
|
||||
} else {
|
||||
fmt.Println("[ ]", res.filename)
|
||||
line = fmt.Sprintf("[ ] %s", res.filename)
|
||||
}
|
||||
if !quiet {
|
||||
fmt.Println(line)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Printf("Applied: %d\n", totalApplied)
|
||||
fmt.Printf("Pending: %d\n", len(results)-totalApplied)
|
||||
totalPending := len(results) - totalApplied
|
||||
if !quiet {
|
||||
fmt.Println()
|
||||
fmt.Printf("Applied: %d\n", totalApplied)
|
||||
fmt.Printf("Pending: %d\n", totalPending)
|
||||
}
|
||||
|
||||
return nil
|
||||
return totalPending, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue