Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/actions/newdomain/format.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package newdomain

import (
"github.com/Drafteame/draft/internal/data"
"github.com/Drafteame/draft/internal/pkg/format"
)

func (nd *NewDomain) format() error {
return format.Code()
paths := []string{nd.input.DomainPath}

// For Postgres, also format the modified provider files
if nd.input.DBType == data.DBTypePostgres {
paths = append(paths, "pkg/providers")
}

return format.Code(paths...)
}
3 changes: 2 additions & 1 deletion internal/actions/newlambda/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import (
)

func (nl *NewLambda) format() error {
return format.Code()
depsPath := nl.input.ServicePath + "/deps.go"
return format.Code(nl.lambdaPath, depsPath)
}
21 changes: 17 additions & 4 deletions internal/pkg/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,29 @@ import (
"github.com/Drafteame/draft/internal/pkg/exec"
)

// Code formats generated code using goimports-reviser
func Code() error {
// Code formats generated code using goimports-reviser.
// If no paths are provided, formats all files (./...).
// Otherwise, formats only the specified paths.
func Code(paths ...string) error {
var err error

spin := spinner.New().Title("Formatting generated code")

action := func() {
_, errExec := exec.Command("goimports-reviser ./...")
target := "./..."
if len(paths) > 0 {
target = ""
for i, path := range paths {
if i > 0 {
target += " "
}
target += path
}
}

_, errExec := exec.Command(fmt.Sprintf("goimports-reviser %s", target))
if errExec != nil {
err = fmt.Errorf("command 'goimports-reviser ./...' failed: %w", errExec)
err = fmt.Errorf("command 'goimports-reviser %s' failed: %w", target, errExec)
}
}

Expand Down