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

Pongo2 support #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Pongo2 support #18

wants to merge 5 commits into from

Conversation

tcpj
Copy link

@tcpj tcpj commented Apr 25, 2018

  • Support for pongo2 template system (jinja2-like)
  • Slightly refactored for better readability

@tcpj
Copy link
Author

tcpj commented Apr 25, 2018

cc @dohnto @jprukner

Copy link

@dohnto dohnto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Generally ok
  • Templar? Is it a real world? :D
  • I would prefer to change the directory structure to create a file just with an interface and separate files with implementation in a subfolder(s). Although I am not really sure what is the standard way, but this is messy.

@freznicek @lksv @FUSAKLA

pongo.go Outdated
"os"
"strings"

"github.com/flosch/pongo2"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoudn't you update glide files?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should!

flag.BoolVar(&doExec, "exec", false, "Activates exec by command. First non-flag arguments is the command, the rest are it's arguments.")
flag.BoolVar(&printVersion, "version", false, "Prints version.")
flag.Var(&envFileList, "env-file", "Additional file with environment variables. Can be passed multiple times.")
flag.StringVar(&delimLeft, "delim-left", "", "Override default left delimiter {{.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should at least mention, that delims are used only with default engine. And maybe we should think a way how to make this more general.

Copy link
Author

@tcpj tcpj Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a custom help for every engine? Every engine could have its own options. I'll think about it.

templar = &PongoTemplar{
Source: source,
}
default:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about failing in default and have a case "text/template"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That breaks backwards compatibility. You would have to change every Dockerfile with goenvtemplator entrypoint... for example.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean

+	flag.StringVar(&engine, "engine", "text/template", "Override default text/template [support: pongo2]")

and to have a case "text/template" and default if an user passes --engine=foo-bar to fail and not to use default text/template engine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truly looks better and more deterministic. Will fix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 there should be sanity check on the engine type or at least warning about using the default go template engine

if err := generateTemplates(tmpls, debugTemplates, delimLeft, delimRight); err != nil {
log.Fatal(err)
if err := generateTemplates(tmpls, delimLeft, delimRight, engine); err != nil {
panic(err)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain the reason of the change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to panic than proceed to execute a command with partially generated templates.

Copy link

@dohnto dohnto Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://golang.org/pkg/log/#Fatal

Fatal calls os.Exit(1) so it will not proceed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, didn't know that. Will fix.

pongo.go Outdated
@@ -25,6 +26,8 @@ func (templar *PongoTemplar) generateTemplate() (string, error) {
context[key] = value
}

Debug("Using context %v", context)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not a fan the co called "debug" feature, and I am still not. There might be a sensitive information you will be printing...

t.destination = strings.TrimSpace(parts[1])
} else {
parts := strings.SplitN(value, ":", 2)
if len(parts) < 2 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't like this change...

If you pass foo:bar:tralala than everything is working even thought the tralala is omitted and user gets no invoice about this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm taking back this comment. I've misunderstood how the SplitN function works.

return nil
}

func readSource(templatePath string) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I woud prefer naming this readFile since you already have writeFile

templar = &PongoTemplar{
Source: source,
}
default:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 there should be sanity check on the engine type or at least warning about using the default go template engine

func writeFile(destinationPath string, data string) error {
if !filepath.IsAbs(destinationPath) {
log.Fatalf("Destination path '%s' is not absolute!", destinationPath)
return errors.New("absolute path error")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is dead code, I would prefere to remove the Fatal logging line.

@dohnto
Copy link

dohnto commented Jul 16, 2018

LGTM, can you please squash, update changelog and write docs?

@tcpj
Copy link
Author

tcpj commented Jul 16, 2018

sure i can

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.

4 participants