-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add zap logger - Add zapFactory to build the logger - Add LogService to manage logging - Add verbose and silent flags
- Loading branch information
1 parent
409a599
commit 889e2e9
Showing
19 changed files
with
306 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"log" | ||
|
||
"github.com/migratemgr8/mgr8/domain" | ||
"github.com/migratemgr8/mgr8/drivers" | ||
"github.com/migratemgr8/mgr8/infrastructure" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var defaultDriverName = string(drivers.Postgres) | ||
|
||
type CommandExecutor interface { | ||
execute(args []string, databaseURL string, migrationsDir string, driver domain.Driver) error | ||
execute(args []string, databaseURL string, migrationsDir string, driver domain.Driver, verbosity infrastructure.LogLevel) error | ||
} | ||
|
||
type Command struct { | ||
driverName string | ||
databaseURL string | ||
migrationsDir string | ||
cmd CommandExecutor | ||
|
||
cmd CommandExecutor | ||
} | ||
|
||
func (c *Command) Execute(cmd *cobra.Command, args []string) { | ||
verbose, err := cmd.Flags().GetBool(verboseFlag) | ||
if err != nil { | ||
panic(err) | ||
} | ||
silent, err := cmd.Flags().GetBool(silentFlag) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
driver, err := drivers.GetDriver(c.driverName) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = c.cmd.execute(args, c.databaseURL, c.migrationsDir, driver) | ||
logLevel, err := c.getLogLevel(verbose, silent) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = c.cmd.execute(args, c.databaseURL, c.migrationsDir, driver, logLevel) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func (c *Command) getLogLevel(verbose, silent bool) (infrastructure.LogLevel, error) { | ||
if silent && verbose { | ||
return "", errors.New("flags silent and verbose are mutually exclusive") | ||
} | ||
|
||
if silent { | ||
return infrastructure.CriticalLogLevel, nil | ||
} | ||
|
||
if verbose { | ||
return infrastructure.DebugLogLevel, nil | ||
} | ||
|
||
return infrastructure.InfoLogLevel, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.