Skip to content

[WIP] pkg/generator: add cmd/main.go generator#22

Closed
fanminshi wants to merge 2 commits intooperator-framework:masterfrom
fanminshi:generate_main
Closed

[WIP] pkg/generator: add cmd/main.go generator#22
fanminshi wants to merge 2 commits intooperator-framework:masterfrom
fanminshi:generate_main

Conversation

@fanminshi
Copy link
Copy Markdown
Contributor

add github.com/dave/jennifer/jen dependency.
use Jennifer code generator to auto generate *.go files.
generate cmd/main.go as part of operator application generation.

@fanminshi fanminshi changed the title pkg/generator: add cmd/main.go generator [WIP] pkg/generator: add cmd/main.go generator Feb 20, 2018
@fanminshi fanminshi mentioned this pull request Feb 20, 2018
21 tasks
@fanminshi
Copy link
Copy Markdown
Contributor Author

fanminshi commented Feb 20, 2018

this depends on #21 because it uses some constants defined in that pr.

@hongchaodeng
Copy link
Copy Markdown
Contributor

hongchaodeng commented Feb 20, 2018

I would suggest to use go library text/template to generate template files instead of using jennifer.

First of all, the library itself is very confusing. Looking at the code:

	// func main() {..}
	file.Func().Id("main").Params().Block(
		// namespace := "default"
		Id("namespace").Op(":=").Lit("default"),
		// sdk.Watch(...)
		Qual(sdkImport, "Watch").Call(
			Qual(apiImport, servicePlural),
			Id("namespace"),
			Qual(apiImport, service),
		),
		// sdk.Handle(...)
		Qual(stubImport, "Handle").Call(
			Op("&").Qual(stubImport, "Handler{}"),
		),
		// sdk.Run(...)
		Qual(sdkImport, "Run").Call(
			Qual("context", "TODO").Call(),
		),
	)

Every line of code needs explanation in order to understand it. The template should just describe it itself.

Second, the jennifer library hasn't seen major activities for more than 6 months: https://github.com/dave/jennifer/graphs/contributors.

@fanminshi
Copy link
Copy Markdown
Contributor Author

@hongchaodeng I can give text/template a try. what's nice about jennifer is that it handles imports nicely and also it is strict.

@hongchaodeng
Copy link
Copy Markdown
Contributor

I understand that jennifer has put some syntax meaning into the library. It's a good direction. But it is too early and immature a project.

@fanminshi
Copy link
Copy Markdown
Contributor Author

@hongchaodeng let me explore other code generation tools.

@fanminshi
Copy link
Copy Markdown
Contributor Author

close this in favor of #29

@fanminshi fanminshi closed this Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants