-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: master
Are you sure you want to change the base?
Pongo2 support #18
Conversation
tcpj
commented
Apr 25, 2018
- Support for pongo2 template system (jinja2-like)
- Slightly refactored for better readability
There was a problem hiding this 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.
pongo.go
Outdated
"os" | ||
"strings" | ||
|
||
"github.com/flosch/pongo2" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should!
goenvtemplator.go
Outdated
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 {{.") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
goenvtemplator.go
Outdated
templar = &PongoTemplar{ | ||
Source: source, | ||
} | ||
default: |
There was a problem hiding this comment.
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"
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
goenvtemplator.go
Outdated
if err := generateTemplates(tmpls, debugTemplates, delimLeft, delimRight); err != nil { | ||
log.Fatal(err) | ||
if err := generateTemplates(tmpls, delimLeft, delimRight, engine); err != nil { | ||
panic(err) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
goenvtemplator.go
Outdated
return nil | ||
} | ||
|
||
func readSource(templatePath string) (string, error) { |
There was a problem hiding this comment.
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
goenvtemplator.go
Outdated
templar = &PongoTemplar{ | ||
Source: source, | ||
} | ||
default: |
There was a problem hiding this comment.
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
goenvtemplator.go
Outdated
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") |
There was a problem hiding this comment.
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.
LGTM, can you please squash, update changelog and write docs? |
sure i can |