tests-always-included / mo

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

Pass arguments to function as environment variable MO_ALLOW_FUNCTION_ARGUMENTS #32

Closed andreax79 closed 5 years ago

andreax79 commented 5 years ago

Hi! I'm mo-addicted. I need to use it in all my scripts :) I created a little patch for exporting function arguments as environment variable MO_ARGS when MO_ALLOW_FUNCTION_ARGUMENTS is not enabled. Thanks, Andrea

fidian commented 5 years ago

I like the idea. Are you open to making changes? I've got some suggestions.

I would like to always have MO_ARGS set to $3 (trimmed) and then optionally pass $3 as an argument to the function when MO_ALLOW_FUNCTION_ARGUMENTS is set?

The name MO_ARGS strikes me as having multiple possible meanings. I could interpret it as "arguments passed to the mo command". To avoid confusion, would you be willing to rename it to MO_FUNCTION_ARGS or use another name that helps distinguish it from my alternate interpretation?

It would also be great if you would be willing to add an example that illustrates how this could be used. You and I both know that the tests show off this ability, but sometimes a simple example as a demonstration can work wonders and help explain it another way to help make it more understandable.

All of these are optional. If you don't want to do it then I will try to find time to do it myself in a branch that has your commit and eventually merge it into master.

Thank you so much for this idea. It's a great addition and I look forward to including it.

fidian commented 5 years ago

Beautiful, thanks for doing this!

andreax79 commented 5 years ago

I'm not not very satisfied of the usage example, but better than nothing :)