Add "echo" as logger
This allow to test ouput, and specify ouput other then os.Stdout
This commit is contained in:
parent
23e4547e52
commit
5fd9bc851b
6 changed files with 315 additions and 117 deletions
33
app/app.go
33
app/app.go
|
|
@ -2,10 +2,13 @@ package app
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"gitlab.com/revalus/grm/commands"
|
||||
"gitlab.com/revalus/grm/config"
|
||||
"gitlab.com/revalus/grm/echo"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -19,15 +22,12 @@ const (
|
|||
type GitRepositoryManager struct {
|
||||
cliArguments config.CliArguments
|
||||
configuration config.Configuration
|
||||
console ConsoleOutput
|
||||
}
|
||||
|
||||
func (g *GitRepositoryManager) Parse(args []string) {
|
||||
co := ConsoleOutput{}
|
||||
|
||||
checkCriticalError := func(err error) {
|
||||
if err != nil {
|
||||
co.ErrorfMsg("%v", err.Error())
|
||||
fmt.Printf("Error: %v", err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
|
@ -43,21 +43,22 @@ func (g *GitRepositoryManager) Parse(args []string) {
|
|||
|
||||
configuration, err := config.GetRepositoryConfig(configFileContent, fileExcension)
|
||||
checkCriticalError(err)
|
||||
co.Color = arguments.Color
|
||||
|
||||
g.console = co
|
||||
g.cliArguments = arguments
|
||||
g.configuration = configuration
|
||||
}
|
||||
|
||||
func (g *GitRepositoryManager) Run() int {
|
||||
func (g *GitRepositoryManager) Run(w io.Writer) int {
|
||||
|
||||
echo.Color(g.cliArguments.Color)
|
||||
echo.Output(w)
|
||||
|
||||
exitCode := 0
|
||||
|
||||
if len(g.cliArguments.LimitTags) != 0 {
|
||||
err := g.limitTags()
|
||||
if err != nil {
|
||||
g.console.ErrorfMsg(err.Error())
|
||||
echo.ErrorfMsg(err.Error())
|
||||
exitCode = 1
|
||||
}
|
||||
}
|
||||
|
|
@ -65,40 +66,40 @@ func (g *GitRepositoryManager) Run() int {
|
|||
if g.cliArguments.LimitName != "" {
|
||||
err := g.limitName()
|
||||
if err != nil {
|
||||
g.console.ErrorfMsg(err.Error())
|
||||
echo.ErrorfMsg(err.Error())
|
||||
exitCode = 1
|
||||
}
|
||||
}
|
||||
|
||||
if g.cliArguments.Sync && exitCode == 0 {
|
||||
g.console.InfoFMsg("Synchronizing repositories")
|
||||
echo.InfoFMsg("Synchronizing repositories")
|
||||
sync := commands.NewSynchronizer(g.configuration.Workspace)
|
||||
g.runCommand(sync)
|
||||
g.console.InfoFMsg("All repositories are synced")
|
||||
echo.InfoFMsg("All repositories are synced")
|
||||
}
|
||||
|
||||
if g.cliArguments.Status && exitCode == 0 {
|
||||
g.console.InfoFMsg("Current status of repositories")
|
||||
echo.InfoFMsg("Current status of repositories")
|
||||
status := commands.NewStatusChecker(g.configuration.Workspace)
|
||||
g.runCommand(status)
|
||||
}
|
||||
|
||||
if g.cliArguments.Version {
|
||||
g.console.InfoFMsg("Current version: %v", VERSION)
|
||||
echo.InfoFMsg("Current version: %v", VERSION)
|
||||
}
|
||||
return exitCode
|
||||
}
|
||||
|
||||
func (g GitRepositoryManager) describeStatus(status commands.CommandStatus) {
|
||||
if status.Error {
|
||||
g.console.ErrorStatusF("Repository \"%v\": an error occurred: %v", status.Name, status.Message)
|
||||
echo.RedMessageF("Repository \"%v\": an error occurred: %v", status.Name, status.Message)
|
||||
return
|
||||
}
|
||||
|
||||
if status.Changed {
|
||||
g.console.ChangedStatusF("Repository \"%v\": %v", status.Name, status.Message)
|
||||
echo.YellowMessageF("Repository \"%v\": %v", status.Name, status.Message)
|
||||
} else {
|
||||
g.console.UnchangedStatusF("Repository \"%v\": %v", status.Name, status.Message)
|
||||
echo.GreenMessageF("Repository \"%v\": %v", status.Name, status.Message)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue