Restructure project directories
Follow the standard of all go projects
This commit is contained in:
parent
741f18efd1
commit
5445ce1ccf
@ -7,11 +7,12 @@ tasks:
|
|||||||
silent: true
|
silent: true
|
||||||
test:
|
test:
|
||||||
cmds:
|
cmds:
|
||||||
- go test $(find . -name "*.go" -exec dirname {} \; | uniq | grep '/') -cover
|
- go test $(find './internal' -name "*.go" -exec dirname {} \; | uniq | grep '/') -cover
|
||||||
build:
|
build:
|
||||||
|
dir: "cmd"
|
||||||
cmds:
|
cmds:
|
||||||
- mkdir -p build
|
- mkdir -p ../build
|
||||||
- go build -o build/grm
|
- go build -o ../build/grm
|
||||||
|
|
||||||
install:
|
install:
|
||||||
deps:
|
deps:
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitlab.com/revalus/grm/internal/grm"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gitlab.com/revalus/grm/app"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
app := app.GitRepositoryManager{}
|
app := grm.GitRepositoryManager{}
|
||||||
err := app.Parse(os.Args)
|
err := app.Parse(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(2)
|
os.Exit(2)
|
@ -1,6 +1,8 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import "gitlab.com/revalus/grm/config"
|
import (
|
||||||
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
type Command interface {
|
type Command interface {
|
||||||
Command(repoCfg config.RepositoryConfig) CommandStatus
|
Command(repoCfg config.RepositoryConfig) CommandStatus
|
@ -2,6 +2,7 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
@ -10,7 +11,6 @@ import (
|
|||||||
gitcfg "github.com/go-git/go-git/v5/config"
|
gitcfg "github.com/go-git/go-git/v5/config"
|
||||||
"github.com/go-git/go-git/v5/plumbing/cache"
|
"github.com/go-git/go-git/v5/plumbing/cache"
|
||||||
"github.com/go-git/go-git/v5/storage/filesystem"
|
"github.com/go-git/go-git/v5/storage/filesystem"
|
||||||
"gitlab.com/revalus/grm/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestSetup struct {
|
type TestSetup struct {
|
@ -2,11 +2,11 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
"gitlab.com/revalus/grm/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type StatusChecker struct {
|
type StatusChecker struct {
|
@ -2,13 +2,13 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5/memfs"
|
"github.com/go-git/go-billy/v5/memfs"
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
"github.com/go-git/go-git/v5/storage/memory"
|
"github.com/go-git/go-git/v5/storage/memory"
|
||||||
"gitlab.com/revalus/grm/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIfBranchesAreEqual(t *testing.T) {
|
func TestIfBranchesAreEqual(t *testing.T) {
|
@ -2,9 +2,9 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"gitlab.com/revalus/grm/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Synchronizer struct {
|
type Synchronizer struct {
|
@ -2,10 +2,9 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitlab.com/revalus/grm/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSyncInit(t *testing.T) {
|
func TestSyncInit(t *testing.T) {
|
@ -1,31 +1,30 @@
|
|||||||
package app
|
package grm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
commands2 "gitlab.com/revalus/grm/internal/commands"
|
||||||
|
config2 "gitlab.com/revalus/grm/internal/config"
|
||||||
|
"gitlab.com/revalus/grm/internal/echo"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"gitlab.com/revalus/grm/commands"
|
|
||||||
"gitlab.com/revalus/grm/config"
|
|
||||||
"gitlab.com/revalus/grm/echo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AppName = "Git repository manager"
|
AppName = "Git repository manager"
|
||||||
AppDescription = "Manage your repository with simple app"
|
AppDescription = "Manage your repository with simple grm"
|
||||||
VERSION = "0.3.0"
|
VERSION = "0.3.0"
|
||||||
errNotFoundTags = "no repository was found with the specified tags"
|
errNotFoundTags = "no repository was found with the specified tags"
|
||||||
errNotFoundName = "no repository was found with the specified name"
|
errNotFoundName = "no repository was found with the specified name"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitRepositoryManager struct {
|
type GitRepositoryManager struct {
|
||||||
cliArguments config.CliArguments
|
cliArguments config2.CliArguments
|
||||||
configuration config.Configuration
|
configuration config2.Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GitRepositoryManager) Parse(args []string) error {
|
func (g *GitRepositoryManager) Parse(args []string) error {
|
||||||
arguments, err := config.ParseCliArguments(AppName, AppDescription, args)
|
arguments, err := config2.ParseCliArguments(AppName, AppDescription, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error: %v", err.Error())
|
fmt.Printf("Error: %v", err.Error())
|
||||||
return err
|
return err
|
||||||
@ -43,7 +42,7 @@ func (g *GitRepositoryManager) Parse(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration, err := config.GetRepositoryConfig(configFileContent, fileExtension)
|
configuration, err := config2.GetRepositoryConfig(configFileContent, fileExtension)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error: %v", err.Error())
|
fmt.Printf("Error: %v", err.Error())
|
||||||
return err
|
return err
|
||||||
@ -79,14 +78,14 @@ func (g *GitRepositoryManager) Run(w io.Writer) int {
|
|||||||
|
|
||||||
if g.cliArguments.Sync && exitCode == 0 {
|
if g.cliArguments.Sync && exitCode == 0 {
|
||||||
echo.InfoFMsg("Synchronizing repositories")
|
echo.InfoFMsg("Synchronizing repositories")
|
||||||
sync := commands.NewSynchronizer(g.configuration.Workspace)
|
sync := commands2.NewSynchronizer(g.configuration.Workspace)
|
||||||
g.runCommand(sync)
|
g.runCommand(sync)
|
||||||
echo.InfoFMsg("All repositories are synced")
|
echo.InfoFMsg("All repositories are synced")
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.cliArguments.Status && exitCode == 0 {
|
if g.cliArguments.Status && exitCode == 0 {
|
||||||
echo.InfoFMsg("Current status of repositories")
|
echo.InfoFMsg("Current status of repositories")
|
||||||
status := commands.NewStatusChecker(g.configuration.Workspace)
|
status := commands2.NewStatusChecker(g.configuration.Workspace)
|
||||||
g.runCommand(status)
|
g.runCommand(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +95,7 @@ func (g *GitRepositoryManager) Run(w io.Writer) int {
|
|||||||
return exitCode
|
return exitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func describeStatus(status commands.CommandStatus) {
|
func describeStatus(status commands2.CommandStatus) {
|
||||||
if status.Error {
|
if status.Error {
|
||||||
echo.RedMessageF("Repository \"%v\": an error occurred: %v", status.Name, status.Message)
|
echo.RedMessageF("Repository \"%v\": an error occurred: %v", status.Name, status.Message)
|
||||||
return
|
return
|
||||||
@ -110,7 +109,7 @@ func describeStatus(status commands.CommandStatus) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GitRepositoryManager) limitTags() error {
|
func (g *GitRepositoryManager) limitTags() error {
|
||||||
limitedTagsTmp := []config.RepositoryConfig{}
|
limitedTagsTmp := []config2.RepositoryConfig{}
|
||||||
|
|
||||||
for _, item := range g.configuration.Repositories {
|
for _, item := range g.configuration.Repositories {
|
||||||
if checkAnyOfItemInSlice(item.Tags, g.cliArguments.LimitToTags) {
|
if checkAnyOfItemInSlice(item.Tags, g.cliArguments.LimitToTags) {
|
||||||
@ -127,14 +126,14 @@ func (g *GitRepositoryManager) limitTags() error {
|
|||||||
func (g *GitRepositoryManager) limitName() error {
|
func (g *GitRepositoryManager) limitName() error {
|
||||||
for _, item := range g.configuration.Repositories {
|
for _, item := range g.configuration.Repositories {
|
||||||
if g.cliArguments.LimitToName == item.Name {
|
if g.cliArguments.LimitToName == item.Name {
|
||||||
g.configuration.Repositories = []config.RepositoryConfig{item}
|
g.configuration.Repositories = []config2.RepositoryConfig{item}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors.New(errNotFoundName)
|
return errors.New(errNotFoundName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GitRepositoryManager) runCommand(cmd commands.Command) {
|
func (g *GitRepositoryManager) runCommand(cmd commands2.Command) {
|
||||||
routines := make(chan struct{}, g.cliArguments.Routines)
|
routines := make(chan struct{}, g.cliArguments.Routines)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
@ -146,7 +145,7 @@ func (g *GitRepositoryManager) runCommand(cmd commands.Command) {
|
|||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
go func(r config.RepositoryConfig) {
|
go func(r config2.RepositoryConfig) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
routines <- struct{}{}
|
routines <- struct{}{}
|
||||||
describeStatus(cmd.Command(r))
|
describeStatus(cmd.Command(r))
|
@ -1,14 +1,13 @@
|
|||||||
package app
|
package grm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitlab.com/revalus/grm/internal/commands"
|
||||||
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
|
"gitlab.com/revalus/grm/internal/echo"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitlab.com/revalus/grm/commands"
|
|
||||||
"gitlab.com/revalus/grm/config"
|
|
||||||
"gitlab.com/revalus/grm/echo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeCommandToTest struct {
|
type FakeCommandToTest struct {
|
||||||
@ -92,7 +91,7 @@ func TestParseApplication(t *testing.T) {
|
|||||||
os.Remove(workdir)
|
os.Remove(workdir)
|
||||||
})
|
})
|
||||||
|
|
||||||
args := []string{"custom-app", "sync", "-c", configFile}
|
args := []string{"custom-grm", "sync", "-c", configFile}
|
||||||
grm := GitRepositoryManager{}
|
grm := GitRepositoryManager{}
|
||||||
grm.Parse(args)
|
grm.Parse(args)
|
||||||
|
|
@ -1,12 +1,11 @@
|
|||||||
package app
|
package grm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitlab.com/revalus/grm/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getFileContent(pathToFile string) ([]byte, error) {
|
func getFileContent(pathToFile string) ([]byte, error) {
|
@ -1,10 +1,9 @@
|
|||||||
package app
|
package grm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitlab.com/revalus/grm/internal/config"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitlab.com/revalus/grm/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetFileExtension(t *testing.T) {
|
func TestGetFileExtension(t *testing.T) {
|
Loading…
Reference in New Issue
Block a user