mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-11 23:50:04 +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
30
main.go
30
main.go
|
|
@ -17,9 +17,10 @@ func main() {
|
|||
|
||||
app := NewApp()
|
||||
err := app.Run(os.Args)
|
||||
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,8 +106,33 @@ func NewApp() *cli.App {
|
|||
{
|
||||
Name: "status",
|
||||
Usage: "List applied and pending migrations",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "exit-code",
|
||||
Usage: "return 1 if there are pending migrations",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "quiet",
|
||||
Usage: "don't output any text (implies --exit-code)",
|
||||
},
|
||||
},
|
||||
Action: action(func(db *dbmate.DB, c *cli.Context) error {
|
||||
return db.Status()
|
||||
setExitCode := c.Bool("exit-code")
|
||||
quiet := c.Bool("quiet")
|
||||
if quiet {
|
||||
setExitCode = true
|
||||
}
|
||||
|
||||
pending, err := db.Status(quiet)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if pending > 0 && setExitCode {
|
||||
return cli.NewExitError("", 1)
|
||||
}
|
||||
|
||||
return nil
|
||||
}),
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue