Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Move object-impl generator to cmd #462

Merged
merged 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions internal/cmd/objectimpl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# docgen

`objectimpl` is a tool that generates boilerplate functions for manifest objects
in order to implement `manifest.Object` interface.

It utilizes `text/template` to generate the code.

## Usage

Add the following `generate` directive to the file that contains the `manifest.Object` object definition.
Replace the `<OBJECT_KIND>` with the struct name of your object, e.g. `Project`.

```go
//go:generate go run ../../../internal/cmd/objectimpl <OBJECT_KIND>
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"unicode"
)

//go:embed generate-object-impl.tpl
//go:embed object.tmpl
var templateStr string

type generator struct {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Agent
//go:generate go run ../../../internal/cmd/objectimpl Agent

// New creates new Agent instance.
func New(metadata Metadata, spec Spec) Agent {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/agent/agent_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Alert
//go:generate go run ../../../internal/cmd/objectimpl Alert

// New creates a new Alert based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) Alert {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/alert/alert_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/alertmethod/alert_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go AlertMethod
//go:generate go run ../../../internal/cmd/objectimpl AlertMethod

// New creates a new AlertMethod based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) AlertMethod {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/alertmethod/alert_method_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/alertpolicy/alert_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go AlertPolicy
//go:generate go run ../../../internal/cmd/objectimpl AlertPolicy

func New(metadata Metadata, spec Spec) AlertPolicy {
return AlertPolicy{
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/alertpolicy/alert_policy_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/alertsilence/alert_silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go AlertSilence
//go:generate go run ../../../internal/cmd/objectimpl AlertSilence

// New creates a new AlertSilence based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) AlertSilence {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/alertsilence/alert_silence_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/annotation/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go Annotation
//go:generate go run ../../../internal/cmd/objectimpl Annotation

// New creates a new Annotation based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) Annotation {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/annotation/annotation_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/budgetadjustment/budget_adjustment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go BudgetAdjustment
//go:generate go run ../../../internal/cmd/objectimpl BudgetAdjustment

func New(metadata Metadata, spec Spec) BudgetAdjustment {
return BudgetAdjustment{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/dataexport/data_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go DataExport
//go:generate go run ../../../internal/cmd/objectimpl DataExport

// New creates a new DataExport based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) DataExport {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/dataexport/data_export_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/direct/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Direct
//go:generate go run ../../../internal/cmd/objectimpl Direct

func New(metadata Metadata, spec Spec) Direct {
return Direct{
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/direct/direct_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifest/v1alpha/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ func Test_ParseObject_EnsureAllKindsAreParsed(t *testing.T) {
}
}

func Test_ParseThis(t *testing.T) {
data, format := readParserTestFile(t, "test.yaml")
_, err := ParseObject(data, manifest.KindSLO, format)
assert.NoError(t, err)
//yaml.NewEncoder()
}

func readParserTestFile(t *testing.T, filename string) ([]byte, manifest.ObjectFormat) {
t.Helper()
data, err := parserTestData.ReadFile(filepath.Join("test_data", filename))
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Project
//go:generate go run ../../../internal/cmd/objectimpl Project

// New creates a new Project based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) Project {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/project/project_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/rolebinding/role_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go RoleBinding
//go:generate go run ../../../internal/cmd/objectimpl RoleBinding

func New(metadata Metadata, spec Spec) RoleBinding {
return RoleBinding{
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/rolebinding/role_binding_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go Service
//go:generate go run ../../../internal/cmd/objectimpl Service

// New creates a new Service based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) Service {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/service/service_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/slo/slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
)

//go:generate go run ../../../scripts/generate-object-impl.go SLO
//go:generate go run ../../../internal/cmd/objectimpl SLO

// New creates a new SLO based on provided Metadata nad Spec.
func New(metadata Metadata, spec Spec) SLO {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/slo/slo_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest/v1alpha/usergroup/user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/nobl9/nobl9-go/manifest"
)

//go:generate go run ../../../scripts/generate-object-impl.go UserGroup
//go:generate go run ../../../internal/cmd/objectimpl UserGroup

func New(metadata Metadata, spec Spec) UserGroup {
return UserGroup{
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/usergroup/user_group_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading