Add possiblity to limit actions to tagged or named repository
This commit is contained in:
parent
5c98ab6554
commit
23e4547e52
11 changed files with 345 additions and 24 deletions
59
app/app.go
59
app/app.go
|
|
@ -1,6 +1,7 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"gitlab.com/revalus/grm/commands"
|
||||
|
|
@ -10,7 +11,9 @@ import (
|
|||
const (
|
||||
APP_NAME = "Git repository manager"
|
||||
APP_DESCRIPTION = "Manage your repository with simple app"
|
||||
VERSION = "0.2.0"
|
||||
VERSION = "0.3.0"
|
||||
errNotFoundTags = "no repository was found with the specified tags"
|
||||
errNotFoundName = "no repository was found with the specified name"
|
||||
)
|
||||
|
||||
type GitRepositoryManager struct {
|
||||
|
|
@ -47,17 +50,35 @@ func (g *GitRepositoryManager) Parse(args []string) {
|
|||
g.configuration = configuration
|
||||
}
|
||||
|
||||
func (g *GitRepositoryManager) Run() {
|
||||
if g.cliArguments.Sync {
|
||||
func (g *GitRepositoryManager) Run() int {
|
||||
|
||||
exitCode := 0
|
||||
|
||||
if len(g.cliArguments.LimitTags) != 0 {
|
||||
err := g.limitTags()
|
||||
if err != nil {
|
||||
g.console.ErrorfMsg(err.Error())
|
||||
exitCode = 1
|
||||
}
|
||||
}
|
||||
|
||||
if g.cliArguments.LimitName != "" {
|
||||
err := g.limitName()
|
||||
if err != nil {
|
||||
g.console.ErrorfMsg(err.Error())
|
||||
exitCode = 1
|
||||
}
|
||||
}
|
||||
|
||||
if g.cliArguments.Sync && exitCode == 0 {
|
||||
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.Status {
|
||||
if g.cliArguments.Status && exitCode == 0 {
|
||||
g.console.InfoFMsg("Current status of repositories")
|
||||
status := commands.NewStatusChecker(g.configuration.Workspace)
|
||||
g.runCommand(status)
|
||||
}
|
||||
|
|
@ -65,6 +86,7 @@ func (g *GitRepositoryManager) Run() {
|
|||
if g.cliArguments.Version {
|
||||
g.console.InfoFMsg("Current version: %v", VERSION)
|
||||
}
|
||||
return exitCode
|
||||
}
|
||||
|
||||
func (g GitRepositoryManager) describeStatus(status commands.CommandStatus) {
|
||||
|
|
@ -80,6 +102,31 @@ func (g GitRepositoryManager) describeStatus(status commands.CommandStatus) {
|
|||
}
|
||||
}
|
||||
|
||||
func (g *GitRepositoryManager) limitTags() error {
|
||||
limitedTagsTmp := []config.RepositoryConfig{}
|
||||
|
||||
for _, item := range g.configuration.Repositories {
|
||||
if checkAnyOfItemInSlice(item.Tags, g.cliArguments.LimitTags) {
|
||||
limitedTagsTmp = append(limitedTagsTmp, item)
|
||||
}
|
||||
}
|
||||
if len(limitedTagsTmp) == 0 {
|
||||
return errors.New(errNotFoundTags)
|
||||
}
|
||||
g.configuration.Repositories = reverseRepositoryConfigs(limitedTagsTmp)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GitRepositoryManager) limitName() error {
|
||||
for _, item := range g.configuration.Repositories {
|
||||
if g.cliArguments.LimitName == item.Name {
|
||||
g.configuration.Repositories = []config.RepositoryConfig{item}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New(errNotFoundName)
|
||||
}
|
||||
|
||||
func (g *GitRepositoryManager) runCommand(cmd commands.Command) {
|
||||
statusChan := make(chan commands.CommandStatus)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue