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

Add option to suppress the generation of template if empty #430

Closed
ArcticSnowman opened this issue Nov 14, 2018 · 9 comments
Closed

Add option to suppress the generation of template if empty #430

ArcticSnowman opened this issue Nov 14, 2018 · 9 comments
Assignees

Comments

@ArcticSnowman
Copy link

In our use case the datasource has boolean values to control the generation of certain templates.

There should be an option to suppress the creation of an output file if the template generated no output.

@hairyhenderson
Copy link
Owner

How is "no output" defined? Do you mean exactly zero characters? or is whitespace (maybe a single newline) considered as "no output" too?

I don't think we can adopt this as default behaviour, but optional behaviour controlled by an environment variable may be possible.

@ArcticSnowman
Copy link
Author

ArcticSnowman commented Nov 15, 2018

or a command line option?

Taking a leaf from Helm its zero or just whitespace, I believe..

@ArcticSnowman
Copy link
Author

Going to take a stab at implementing this... any suggestion?
Maybe do it as a cleanup hook?

@hairyhenderson
Copy link
Owner

or a command line option?

I'm not sure I want to add a flag just yet for this. It seems like it'd be a rarely-used option.

Taking a leaf from Helm its zero or just whitespace, I believe..

I didn't know Helm had this behaviour - can you point me to where that's documented?

Going to take a stab at implementing this... any suggestion?
Maybe do it as a cleanup hook?

Sure! A cleanup hook may work, but it'd be a little messy - that presumes that an empty file would be created, then deleted later. I would rather the file only be created if there's data to output (maybe a afero.File implementation that only opens the file the first time a non-whitespace byte passes through)...

@ArcticSnowman
Copy link
Author

@hairyhenderson
Copy link
Owner

Ah. Thanks @ArcticSnowman. Helm's approach is to buffer the data in memory first then write it out if it's got anything. gomplate renders the template directly into the file, streaming rather than buffering it. I prefer the streaming approach.

@ArcticSnowman
Copy link
Author

This make any change to that stream a careful change to do...

@hairyhenderson
Copy link
Owner

@ArcticSnowman not sure if you got anywhere with this, but I've had a stab at it - in #439 - what do you think?

@ArcticSnowman
Copy link
Author

ArcticSnowman commented Nov 28, 2018

Yeah I did not get to it, real work got in the way... I'll take a look...

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

No branches or pull requests

2 participants