Add sync command
This commit is contained in:
commit
5e6a5e23fd
18 changed files with 1077 additions and 0 deletions
89
app/app.go
Normal file
89
app/app.go
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"gitlab.com/revalus/grm/commands"
|
||||
"gitlab.com/revalus/grm/config"
|
||||
)
|
||||
|
||||
const (
|
||||
APP_NAME = "Git repository manager"
|
||||
APP_DESCRIPTION = "Manage your repository with simple app"
|
||||
VERSION = "0.1"
|
||||
)
|
||||
|
||||
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())
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
arguments, err := config.ParseCliArguments(APP_NAME, APP_DESCRIPTION, args)
|
||||
checkCriticalError(err)
|
||||
|
||||
configFileContent, err := getFileContent(arguments.ConfigurationFile)
|
||||
checkCriticalError(err)
|
||||
|
||||
fileExcension, err := getFileExcension(arguments.ConfigurationFile)
|
||||
checkCriticalError(err)
|
||||
|
||||
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() {
|
||||
if g.cliArguments.Sync {
|
||||
|
||||
g.console.InfoFMsg("Synchronizing repositories")
|
||||
println()
|
||||
sync := commands.NewSynchronizer(g.configuration.Workspace)
|
||||
g.runCommand(sync)
|
||||
println()
|
||||
g.console.InfoFMsg("All repositories are synced")
|
||||
}
|
||||
|
||||
if g.cliArguments.Version {
|
||||
g.console.InfoFMsg("Current version: %v", VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
func (g GitRepositoryManager) describeStatus(status commands.CommandStatus) {
|
||||
if status.Error {
|
||||
g.console.ErrorStatusF("Repository \"%v\": an error occurred: %v", status.Name, status.Message)
|
||||
return
|
||||
}
|
||||
|
||||
if status.Changed {
|
||||
g.console.ChangedStatusF("Repository \"%v\": %v", status.Name, status.Message)
|
||||
} else {
|
||||
g.console.UnchangedStatusF("Repository \"%v\": %v", status.Name, status.Message)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GitRepositoryManager) runCommand(cmd commands.Command) {
|
||||
statusChan := make(chan commands.CommandStatus)
|
||||
|
||||
for _, repo := range g.configuration.Repositories {
|
||||
go cmd.Command(repo, statusChan)
|
||||
}
|
||||
|
||||
for range g.configuration.Repositories {
|
||||
g.describeStatus(<-statusChan)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue