Restructure project directories

Follow the standard of all go projects
This commit is contained in:
Mikołaj Pęczkowski 2024-01-13 15:39:40 +01:00
parent 741f18efd1
commit 5445ce1ccf
20 changed files with 39 additions and 42 deletions

View File

@ -7,11 +7,12 @@ tasks:
silent: true
test:
cmds:
- go test $(find . -name "*.go" -exec dirname {} \; | uniq | grep '/') -cover
- go test $(find './internal' -name "*.go" -exec dirname {} \; | uniq | grep '/') -cover
build:
dir: "cmd"
cmds:
- mkdir -p build
- go build -o build/grm
- mkdir -p ../build
- go build -o ../build/grm
install:
deps:

View File

@ -1,14 +1,13 @@
package main
import (
"gitlab.com/revalus/grm/internal/grm"
"os"
"gitlab.com/revalus/grm/app"
)
func main() {
app := app.GitRepositoryManager{}
app := grm.GitRepositoryManager{}
err := app.Parse(os.Args)
if err != nil {
os.Exit(2)

View File

@ -1,6 +1,8 @@
package commands
import "gitlab.com/revalus/grm/config"
import (
"gitlab.com/revalus/grm/internal/config"
)
type Command interface {
Command(repoCfg config.RepositoryConfig) CommandStatus

View File

@ -2,6 +2,7 @@ package commands
import (
"fmt"
"gitlab.com/revalus/grm/internal/config"
"os"
"github.com/go-git/go-billy/v5"
@ -10,7 +11,6 @@ import (
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/storage/filesystem"
"gitlab.com/revalus/grm/config"
)
type TestSetup struct {

View File

@ -2,11 +2,11 @@ package commands
import (
"fmt"
"gitlab.com/revalus/grm/internal/config"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"gitlab.com/revalus/grm/config"
)
type StatusChecker struct {

View File

@ -2,13 +2,13 @@ package commands
import (
"fmt"
"gitlab.com/revalus/grm/internal/config"
"testing"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/storage/memory"
"gitlab.com/revalus/grm/config"
)
func TestIfBranchesAreEqual(t *testing.T) {

View File

@ -2,9 +2,9 @@ package commands
import (
"fmt"
"gitlab.com/revalus/grm/internal/config"
"github.com/go-git/go-git/v5"
"gitlab.com/revalus/grm/config"
)
type Synchronizer struct {

View File

@ -2,10 +2,9 @@ package commands
import (
"fmt"
"gitlab.com/revalus/grm/internal/config"
"os"
"testing"
"gitlab.com/revalus/grm/config"
)
func TestSyncInit(t *testing.T) {

View File

@ -1,31 +1,30 @@
package app
package grm
import (
"errors"
"fmt"
commands2 "gitlab.com/revalus/grm/internal/commands"
config2 "gitlab.com/revalus/grm/internal/config"
"gitlab.com/revalus/grm/internal/echo"
"io"
"sync"
"gitlab.com/revalus/grm/commands"
"gitlab.com/revalus/grm/config"
"gitlab.com/revalus/grm/echo"
)
const (
AppName = "Git repository manager"
AppDescription = "Manage your repository with simple app"
AppDescription = "Manage your repository with simple grm"
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 {
cliArguments config.CliArguments
configuration config.Configuration
cliArguments config2.CliArguments
configuration config2.Configuration
}
func (g *GitRepositoryManager) Parse(args []string) error {
arguments, err := config.ParseCliArguments(AppName, AppDescription, args)
arguments, err := config2.ParseCliArguments(AppName, AppDescription, args)
if err != nil {
fmt.Printf("Error: %v", err.Error())
return err
@ -43,7 +42,7 @@ func (g *GitRepositoryManager) Parse(args []string) error {
return err
}
configuration, err := config.GetRepositoryConfig(configFileContent, fileExtension)
configuration, err := config2.GetRepositoryConfig(configFileContent, fileExtension)
if err != nil {
fmt.Printf("Error: %v", err.Error())
return err
@ -79,14 +78,14 @@ func (g *GitRepositoryManager) Run(w io.Writer) int {
if g.cliArguments.Sync && exitCode == 0 {
echo.InfoFMsg("Synchronizing repositories")
sync := commands.NewSynchronizer(g.configuration.Workspace)
sync := commands2.NewSynchronizer(g.configuration.Workspace)
g.runCommand(sync)
echo.InfoFMsg("All repositories are synced")
}
if g.cliArguments.Status && exitCode == 0 {
echo.InfoFMsg("Current status of repositories")
status := commands.NewStatusChecker(g.configuration.Workspace)
status := commands2.NewStatusChecker(g.configuration.Workspace)
g.runCommand(status)
}
@ -96,7 +95,7 @@ func (g *GitRepositoryManager) Run(w io.Writer) int {
return exitCode
}
func describeStatus(status commands.CommandStatus) {
func describeStatus(status commands2.CommandStatus) {
if status.Error {
echo.RedMessageF("Repository \"%v\": an error occurred: %v", status.Name, status.Message)
return
@ -110,7 +109,7 @@ func describeStatus(status commands.CommandStatus) {
}
func (g *GitRepositoryManager) limitTags() error {
limitedTagsTmp := []config.RepositoryConfig{}
limitedTagsTmp := []config2.RepositoryConfig{}
for _, item := range g.configuration.Repositories {
if checkAnyOfItemInSlice(item.Tags, g.cliArguments.LimitToTags) {
@ -127,14 +126,14 @@ func (g *GitRepositoryManager) limitTags() error {
func (g *GitRepositoryManager) limitName() error {
for _, item := range g.configuration.Repositories {
if g.cliArguments.LimitToName == item.Name {
g.configuration.Repositories = []config.RepositoryConfig{item}
g.configuration.Repositories = []config2.RepositoryConfig{item}
return nil
}
}
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)
var wg sync.WaitGroup
@ -146,7 +145,7 @@ func (g *GitRepositoryManager) runCommand(cmd commands.Command) {
wg.Add(1)
go func(r config.RepositoryConfig) {
go func(r config2.RepositoryConfig) {
defer wg.Done()
routines <- struct{}{}
describeStatus(cmd.Command(r))

View File

@ -1,14 +1,13 @@
package app
package grm
import (
"fmt"
"gitlab.com/revalus/grm/internal/commands"
"gitlab.com/revalus/grm/internal/config"
"gitlab.com/revalus/grm/internal/echo"
"os"
"reflect"
"testing"
"gitlab.com/revalus/grm/commands"
"gitlab.com/revalus/grm/config"
"gitlab.com/revalus/grm/echo"
)
type FakeCommandToTest struct {
@ -92,7 +91,7 @@ func TestParseApplication(t *testing.T) {
os.Remove(workdir)
})
args := []string{"custom-app", "sync", "-c", configFile}
args := []string{"custom-grm", "sync", "-c", configFile}
grm := GitRepositoryManager{}
grm.Parse(args)

View File

@ -1,12 +1,11 @@
package app
package grm
import (
"errors"
"fmt"
"gitlab.com/revalus/grm/internal/config"
"os"
"strings"
"gitlab.com/revalus/grm/config"
)
func getFileContent(pathToFile string) ([]byte, error) {

View File

@ -1,10 +1,9 @@
package app
package grm
import (
"gitlab.com/revalus/grm/internal/config"
"reflect"
"testing"
"gitlab.com/revalus/grm/config"
)
func TestGetFileExtension(t *testing.T) {