Skip to content

Commit

Permalink
feat: rename module
Browse files Browse the repository at this point in the history
  • Loading branch information
raskyld committed Oct 27, 2023
1 parent c5f1ae1 commit 063896c
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 65 deletions.
4 changes: 2 additions & 2 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package cmd

import (
"github.com/Raskyld/go-tektasker/internal/gengo"
"github.com/Raskyld/go-tektasker/internal/genyaml"
"github.com/raskyld/go-tektasker/internal/gengo"
"github.com/raskyld/go-tektasker/internal/genyaml"
"github.com/spf13/cobra"
"path/filepath"
"sigs.k8s.io/controller-tools/pkg/genall"
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package cmd

import (
initGenerator "github.com/Raskyld/go-tektasker/internal/init"
initGenerator "github.com/raskyld/go-tektasker/internal/init"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-tools/pkg/genall"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/markers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package cmd

import (
"errors"
ttmarkers "github.com/Raskyld/go-tektasker/pkg/markers"
ttmarkers "github.com/raskyld/go-tektasker/pkg/markers"
"github.com/spf13/cobra"
"os"
"sigs.k8s.io/controller-tools/pkg/genall/help"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/Raskyld/go-tektasker
module github.com/raskyld/go-tektasker

go 1.21

Expand Down
2 changes: 1 addition & 1 deletion internal/gengo/gen_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"strings"
"text/template"

ttmarkers "github.com/Raskyld/go-tektasker/pkg/markers"
ttmarkers "github.com/raskyld/go-tektasker/pkg/markers"
"sigs.k8s.io/controller-tools/pkg/genall"
"sigs.k8s.io/controller-tools/pkg/markers"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/gengo/gen_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package gengo

import (
"bytes"
ttmarkers "github.com/Raskyld/go-tektasker/pkg/markers"
ttmarkers "github.com/raskyld/go-tektasker/pkg/markers"
"log/slog"
"sigs.k8s.io/controller-tools/pkg/genall"
"sigs.k8s.io/controller-tools/pkg/markers"
Expand Down
2 changes: 1 addition & 1 deletion internal/genyaml/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/json"
"errors"
"fmt"
ttmarkers "github.com/Raskyld/go-tektasker/pkg/markers"
ttmarkers "github.com/raskyld/go-tektasker/pkg/markers"
"go/ast"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down
112 changes: 56 additions & 56 deletions internal/init/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,80 +17,80 @@ limitations under the License.
package init

import (
"fmt"
ttemplate "github.com/Raskyld/go-tektasker/internal/init/internal/template"
ttmarkers "github.com/Raskyld/go-tektasker/pkg/markers"
"log/slog"
"sigs.k8s.io/controller-tools/pkg/genall"
"sigs.k8s.io/controller-tools/pkg/markers"
"strings"
"text/template"
"fmt"
ttemplate "github.com/raskyld/go-tektasker/internal/init/internal/template"
ttmarkers "github.com/raskyld/go-tektasker/pkg/markers"
"log/slog"
"sigs.k8s.io/controller-tools/pkg/genall"
"sigs.k8s.io/controller-tools/pkg/markers"
"strings"
"text/template"
)

type Generator struct {
Logger *slog.Logger
Template *template.Template
TaskName string
Logger *slog.Logger
Template *template.Template
TaskName string
}

func New(logger *slog.Logger, taskName string) *Generator {
gen := &Generator{
Logger: logger,
Template: &template.Template{},
TaskName: taskName,
}

gen.Template.Funcs(template.FuncMap{
"Raw": func(content ...string) string {
return fmt.Sprintf("{{%s}}", strings.Join(content, " "))
},
})

gen.RegisterTemplate(ttemplate.TaskfileName, ttemplate.TaskfileTpl).
RegisterTemplate(ttemplate.DotEnvName, ttemplate.DotEnvTpl).
RegisterTemplate(ttemplate.TaskGoName, ttemplate.TaskGoTpl)

return gen
gen := &Generator{
Logger: logger,
Template: &template.Template{},
TaskName: taskName,
}

gen.Template.Funcs(template.FuncMap{
"Raw": func(content ...string) string {
return fmt.Sprintf("{{%s}}", strings.Join(content, " "))
},
})

gen.RegisterTemplate(ttemplate.TaskfileName, ttemplate.TaskfileTpl).
RegisterTemplate(ttemplate.DotEnvName, ttemplate.DotEnvTpl).
RegisterTemplate(ttemplate.TaskGoName, ttemplate.TaskGoTpl)

return gen
}

func (*Generator) RegisterMarkers(into *markers.Registry) error {
return ttmarkers.Register(into)
return ttmarkers.Register(into)
}

func (g *Generator) RegisterTemplate(name string, tpl string) *Generator {
nt, err := g.Template.New(name).Parse(tpl)
if err != nil {
panic(err)
}
nt, err := g.Template.New(name).Parse(tpl)
if err != nil {
panic(err)
}

g.Template = nt
return g
g.Template = nt
return g
}

func (g *Generator) Generate(output genall.OutputRule) error {
err := g.genFile(output, ttemplate.TaskfileName, "Taskfile.yaml", nil)
if err != nil {
return err
}

err = g.genFile(output, ttemplate.DotEnvName, ".env", nil)
if err != nil {
return err
}

err = g.genFile(output, ttemplate.TaskGoName, "task.go", ttemplate.TaskGoArgs{TaskName: g.TaskName})
if err != nil {
return err
}

return nil
err := g.genFile(output, ttemplate.TaskfileName, "Taskfile.yaml", nil)
if err != nil {
return err
}

err = g.genFile(output, ttemplate.DotEnvName, ".env", nil)
if err != nil {
return err
}

err = g.genFile(output, ttemplate.TaskGoName, "task.go", ttemplate.TaskGoArgs{TaskName: g.TaskName})
if err != nil {
return err
}

return nil
}

func (g *Generator) genFile(output genall.OutputRule, tplName, path string, args any) error {
wr, err := output.Open(nil, path)
if err != nil {
return err
}
wr, err := output.Open(nil, path)
if err != nil {
return err
}

return g.Template.ExecuteTemplate(wr, tplName, args)
return g.Template.ExecuteTemplate(wr, tplName, args)
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package main

import (
"fmt"
"github.com/Raskyld/go-tektasker/cmd"
"github.com/raskyld/go-tektasker/cmd"
"os"
)

Expand Down

0 comments on commit 063896c

Please sign in to comment.