tests-always-included / mo

Mustache templates in pure bash
Other
563 stars 67 forks source link

option to fail on missing environment variable #8

Closed SamuelTilly closed 8 years ago

SamuelTilly commented 9 years ago

Would it be possible to implement a way for the mo application to fail on missing environment variables?

fidian commented 9 years ago

I would not be open to making this the default behavior because it goes against the guidelines:

The most basic tag type is the variable. A {{name}} tag in a basic template will try to find the name key in the current context. If there is no name key, the parent contexts will be checked recursively. If the top context is reached and the name key is still not found, nothing will be rendered.

However, I do like how many things implement a "strict mode" that you may enable. I like this idea and I think it could help prevent errors.

When referencing a variable that is not defined, I would expect the mo command to return a status code that is not 0 to signal that an error has been found. Now comes the critical question: On error, what is displayed to stdout? Nothing? The template as it normally would be displayed?

When I see strict mode implemented, I have seen all three: no output, partial output and abort at the error, full output but additional errors sent to stderr. I'm having trouble deciding what would be appropriate here and somewhat take into account the amount of complexity that this would add to the program (or if it is even possible with how I structured my code).

Do you have any suggestions that you can back up with existing patterns for other tools?

fidian commented 8 years ago

I am open to this idea but I would need to know how mo should respond to various things. Without a better definition and without any feedback, I am closing this issue. Feel free to open a new issue and cover the questions above in order to resume the discussion.

fidian commented 7 years ago

@SamuelTilly, it looks like you are not the only person that wanted this feature. Pull request #15 might do what you want when it gets merged.

SamuelTilly commented 7 years ago

Very nice! thanks for the update