Giter Site home page Giter Site logo

temgo's People

Contributors

malud avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

bemeyert

temgo's Issues

inline editing

tg is a nice replacement for sed when moving ENV vars to config files in docker entrypoint scripts!

however, the tg < template > file semantics forces me to use a separate template file. to keep things easy to read, i would prefer an inline editing mode like sed -i:

tg -i my.conf

the command should be idempotent to avoid changes to the file when the docker container is restarted. ideally, subsequent runs would not write the file at all (because no placeholder was found).

no output without placeholders

When the input stream has no placeholders, tg generates no output:

Expected:

$ echo foo bar | ./tg
foo bar

Actual:

$ echo foo bar | ./tg

With correct placeholders, it works as expected:

$ echo 'foo {{ x }}bar' | ./tg
foo bar

However, incomplete placeholders show the erroneous behaviour, too:

$ echo 'foo {{ }}bar' | ./tg
$ echo 'foo {{x}}bar' | ./tg
$ echo 'foo {{x }}bar' | ./tg

Feature Request: strict mode โ€“ fail on missing vars

I want to propose a strict mode that makes tg fail if a placeholder cannot be replaced.

$ echo '{{ NOT_SET }}' | tg -s
Error: placeholder NOT_SET cannot be replaced
$ echo $?
1

My use case is as usual a docker container's entrypoint. I use tg to fill env vars into configuration files. The configuration file may be broken if a placeholder is not replaced. In the entrypoint I have to check that every env variable used in placeholders is set. This is error prone, because I have at least two places to get it wrong.

With tg -s I would be able to let my set -e entrypoint fail without repeating the variable list.

The stdout variant tg -s > file will empty the file because bash opens the redirection before the command is executed.

But in inplace mode tg -s -i file the output file should not be written at all, if a variable is missing.

Feature Request: Default Values

I would like to define default values for replacements:

KEY={{ VALUE : default }}

especially for docker setups, where tg is used from the entrypoint, I imagine this to be more robust than defining all necessary env vars in docker-compose.yml. this would also eliminate the need to check for all variables from the tg called (entrypoint).

The other nice effect is, that default values can be defined in the target file.

Jinja defaults are quite cumbersome: {{ first_name|default("walter", true) }. therefore my proposal is more bash-oriented, where a default can be written as ${NAME:-walter}. the colon could have arbitrary whitespaces (see above) or we could define {{ VALUE:default }}. it doesn't really matter.

However, it would be handy to allow whitespaces in the default value without the need for quoting:

TITLE={{ PAGE_TITLE : Good news! }}

For processing I would suggest to read everything behind the colon and trim whitespaces.

@malud, what do you think?

Feature request: Make temgo fail if a variable is not set

This feature would be quite useful for saving a lot of code (depends on the number of variables). Currently I do something like this:

set -o errexit
set -o unset

[[ -z ${HTTP_SERVER} ]] && :
[[ -z ${HTTPS_SERVER} ]] && :
[[ -z ${DB_HOSTNAME} ]] && :
[[ -z ${DB_USERNAME} ]] && :
[[ -z ${DB_PASSWORD} ]] && :
[[ -z ${DB_DATABASE} ]] && :
[[ -z ${DB_PORT} ]] && :
[[ -z ${DB_PREFIX} ]] && :
[[ -z ${ADMIN_HTTP_SERVER} ]] && :
[[ -z ${ADMIN_HTTP_CATALOG} ]] && :
[[ -z ${ADMIN_HTTPS_SERVER} ]] && :
[[ -z ${ADMIN_HTTPS_CATALOG} ]] && :

tg -i /app/config.php

If temgo failed when a variable is not set, let's say with the -f switch (force/fail), the above would look like this:

set -o errexit
tg -f -i /app/config.php

The savings on nerves and typing would be enormous ;)

Cheers

Parse error for environment values containing equals rune

The os envs are parsed naively with a strings.Split("=") which leads to wrong value replacements for e.g. a URI with query params.

The Env value https://example.com/?query=param gets mapped to [key]=https://example.com/?query".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.