Skip to content

Commit

Permalink
Merge pull request #3 from ksckaan1/refactor-project
Browse files Browse the repository at this point in the history
big refactor
  • Loading branch information
ksckaan1 authored Dec 15, 2024
2 parents e36acbd + 188c93e commit 7cd23ca
Show file tree
Hide file tree
Showing 76 changed files with 1,391 additions and 1,224 deletions.
81 changes: 81 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
run:
timeout: 5m
go: "1.23.4"
allow-parallel-runners: true
allow-serial-runners: true
concurrency: 8
issues-exit-code: 0
tests: false

linters:
disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- gofumpt
- gosec
- errname
- gocritic
- wrapcheck
- gocognit
- gocyclo
- prealloc
- errorlint

linters-settings:
errcheck:
check-blank: true
check-type-assertions: true
gosimple:
checks: ["all"]
govet:
enable-all: true
settings:
shadow:
strict: true
staticcheck:
checks: ["all"]
gofumpt:
extra-rules: true
gosec:
severity: low
confidence: low
config:
nosec: true
audit: true
show-ignored: true
gocritic:
enabled-tags:
- diagnostic
- style
- performance
- opinionated
gocognit:
min-complexity: 15
gocyclo:
min-complexity: 15
errorlint:
asserts: true
comparison: true
errorf: true

issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- path: '(.+)_test\.go'
linters:
- gocognit
- gocyclo
- govet

output:
print-linter-name: true
print-issued-lines: true
sort-results: true
show-stats: true
31 changes: 15 additions & 16 deletions ...rnal/domain/core/service/config/config.go → config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@ package config

import (
"fmt"
"github.com/ksckaan1/hexago/internal/port"
"os"

"github.com/ksckaan1/hexago/internal/domain/core/dto"
"github.com/ksckaan1/hexago/internal/domain/core/model"
"github.com/samber/do"
"gopkg.in/yaml.v3"
)
yaml "gopkg.in/yaml.v3"

var _ port.ConfigService = (*Config)(nil)
"github.com/ksckaan1/hexago/internal/customerrors"
)

type Config struct {
store model.Config
store store
location string
}

func New(_ *do.Injector) (port.ConfigService, error) {
return &Config{}, nil
func New(location string) (*Config, error) {
return &Config{
location: location,
}, nil
}

func (c *Config) Load(cfgPath string) error {
cfgFile, err := os.Open(cfgPath)
func (c *Config) Load() error {
cfgFile, err := os.Open(c.location)
if err != nil {
return fmt.Errorf("config file not found: %s", cfgPath)
return fmt.Errorf("config file not found: %s", c.location)
}
defer func() {
err = cfgFile.Close()
Expand Down Expand Up @@ -69,13 +68,13 @@ func (c *Config) GetPackageTemplate() string {
return c.store.Templates.Package
}

func (c *Config) GetRunner(runner string) (*model.Runner, error) {
func (c *Config) GetRunner(runner string) (*Runner, error) {
if c.store.Runners == nil {
return nil, dto.ErrRunnerNotImplemented
return nil, customerrors.ErrRunnerNotImplemented
}
v, ok := c.store.Runners[runner]
if !ok {
return nil, dto.ErrRunnerNotImplemented
return nil, customerrors.ErrRunnerNotImplemented
}
return v, nil
}
12 changes: 6 additions & 6 deletions internal/domain/core/model/config.go → config/model.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package model
package config

type Config struct {
Templates Templates `yaml:"templates"`
type store struct {
Runners map[string]*Runner `yaml:"runners"`
Templates templates `yaml:"templates"`
}

type Templates struct {
type templates struct {
Service string `yaml:"service"`
Application string `yaml:"application"`
Infrastructure string `yaml:"infrastructure"`
Expand All @@ -15,10 +15,10 @@ type Templates struct {
type Runner struct {
Cmd string `yaml:"cmd"`
EnvVars []string `yaml:"env"`
Log Log `yaml:"log"`
Log log `yaml:"log"`
}

type Log struct {
type log struct {
Disabled bool `yaml:"disabled"`
SeperateFiles bool `yaml:"seperate_files"`
Overwrite bool `yaml:"overwrite"`
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.23.4
require (
github.com/charmbracelet/huh v0.5.2
github.com/charmbracelet/lipgloss v0.13.0
github.com/samber/do v1.6.0
github.com/samber/lo v1.47.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
Expand Down
194 changes: 194 additions & 0 deletions init_commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package main

import (
"fmt"

"github.com/ksckaan1/hexago/config"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/appcmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/doctorcmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/domaincmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/entrypointcmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/infracmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/initcmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/packagecmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/portcmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/rootcmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/runnercmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/servicecmd"
"github.com/ksckaan1/hexago/internal/domain/core/application/cli/treecmd"
"github.com/ksckaan1/hexago/internal/domain/core/service/project"
"github.com/ksckaan1/hexago/internal/pkg/tuilog"
)

func initCommands(projectService *project.Project, tl *tuilog.TUILog, cfg *config.Config) (*cli.CLI, error) {
// root
rootCmd, err := rootcmd.NewRootCommand()
if err != nil {
return nil, fmt.Errorf("rootcmd.NewRootCommand: %w", err)
}

// init
initCmd, err := initcmd.NewInitCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("initcmd.NewInitCommand: %w", err)
}

// domain
domainCmd, err := domaincmd.NewDomainCommand()
if err != nil {
return nil, fmt.Errorf("domaincmd.NewDomainCommand: %w", err)
}

domainLSCmd, err := domaincmd.NewDomainLSCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("domaincmd.NewDomainLSCommand: %w", err)
}

domainCreateCmd, err := domaincmd.NewDomainCreateCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("domaincmd.NewDomainCreateCommand: %w", err)
}

// service
serviceCmd, err := servicecmd.NewServiceCommand()
if err != nil {
return nil, fmt.Errorf("servicecmd.NewServiceCommand: %w", err)
}

serviceLSCmd, err := servicecmd.NewServiceLSCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("servicecmd.NewServiceLSCommand: %w", err)
}

serviceCreateCmd, err := servicecmd.NewServiceCreateCommand(projectService, cfg, tl)
if err != nil {
return nil, fmt.Errorf("servicecmd.NewServiceCreateCommand: %w", err)
}

// port
portCmd, err := portcmd.NewPortCommand()
if err != nil {
return nil, fmt.Errorf("portcmd.NewPortCommand: %w", err)
}

portLSCmd, err := portcmd.NewPortLSCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("portcmd.NewPortLSCommand: %w", err)
}

// app
appCmd, err := appcmd.NewAppCommand()
if err != nil {
return nil, fmt.Errorf("appcmd.NewAppCommand: %w", err)
}

appLSCmd, err := appcmd.NewAppLSCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("appcmd.NewAppLSCommand: %w", err)
}

appCreateCmd, err := appcmd.NewAppCreateCommand(projectService, cfg, tl)
if err != nil {
return nil, fmt.Errorf("appcmd.NewAppCreateCommand: %w", err)
}

// cmd
entryPointCmd, err := entrypointcmd.NewEntryPointCommand()
if err != nil {
return nil, fmt.Errorf("entrypointcmd.NewEntryPointCommand: %w", err)
}

entryPointLSCmd, err := entrypointcmd.NewEntryPointLSCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("entrypointcmd.NewEntryPointLSCommand: %w", err)
}

entryPointCreateCmd, err := entrypointcmd.NewEntryPointCreateCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("entrypointcmd.NewEntryPointCreateCommand: %w", err)
}

// infra
infraCmd, err := infracmd.NewInfraCommand()
if err != nil {
return nil, fmt.Errorf("infracmd.NewInfraCommand: %w", err)
}

infraLSCmd, err := infracmd.NewInfraLSCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("infracmd.NewInfraLSCommand: %w", err)
}

infraCreateCmd, err := infracmd.NewInfraCreateCommand(projectService, cfg, tl)
if err != nil {
return nil, fmt.Errorf("infracmd.NewInfraCreateCommand: %w", err)
}

// pkg
packageCmd, err := packagecmd.NewPackageCommand()
if err != nil {
return nil, fmt.Errorf("packagecmd.NewPackageCommand: %w", err)
}

packageLSCmd, err := packagecmd.NewPackageLSCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("packagecmd.NewPackageLSCommand: %w", err)
}

packageCreateCmd, err := packagecmd.NewPackageCreateCommand(projectService, cfg, tl)
if err != nil {
return nil, fmt.Errorf("packagecmd.NewPackageCreateCommand: %w", err)
}

// run
runnerCmd, err := runnercmd.NewRunnerCommand(projectService, cfg, tl)
if err != nil {
return nil, fmt.Errorf("runnercmd.NewRunnerCommand: %w", err)
}

// doctor
doctorCmd, err := doctorcmd.NewDoctorCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("doctorcmd.NewDoctorCommand: %w", err)
}

// tree
treeCmd, err := treecmd.NewTreeCommand(projectService, tl)
if err != nil {
return nil, fmt.Errorf("treecmd.NewTreeCommand: %w", err)
}

app, err := cli.New(
rootCmd,
initCmd,
domainCmd,
domainLSCmd,
domainCreateCmd,
serviceCmd,
serviceLSCmd,
serviceCreateCmd,
portCmd,
portLSCmd,
appCmd,
appLSCmd,
appCreateCmd,
entryPointCmd,
entryPointLSCmd,
entryPointCreateCmd,
infraCmd,
infraLSCmd,
infraCreateCmd,
packageCmd,
packageLSCmd,
packageCreateCmd,
runnerCmd,
doctorCmd,
treeCmd,
)
if err != nil {
return nil, fmt.Errorf("cli.New: %w", err)
}

return app, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dto
package customerrors

import (
"errors"
Expand Down
Loading

0 comments on commit 7cd23ca

Please sign in to comment.