diff --git a/.github/workflows/release_notes.sh b/.github/workflows/release_notes.sh index e868116..a08022d 100755 --- a/.github/workflows/release_notes.sh +++ b/.github/workflows/release_notes.sh @@ -14,6 +14,7 @@ wget https://github.com/busyloop/envcat/releases/download/v${VERSION}/envcat-${V chmod +x envcat-${VERSION}.darwin-x86_64 sudo mv envcat-${VERSION}.darwin-x86_64 /usr/local/bin sudo ln -sf /usr/local/bin/envcat-${VERSION}.darwin-x86_64 /usr/local/bin/envcat +sudo ln -sf /usr/local/bin/envcat-${VERSION}.darwin-x86_64 /usr/local/bin/envtpl \`\`\` ## Linux @@ -23,6 +24,7 @@ wget https://github.com/busyloop/envcat/releases/download/v${VERSION}/envcat-${V chmod +x envcat-${VERSION}.linux-x86_64 sudo mv envcat-${VERSION}.linux-x86_64 /usr/bin sudo ln -sf /usr/bin/envcat-${VERSION}.linux-x86_64 /usr/bin/envcat +sudo ln -sf /usr/bin/envcat-${VERSION}.linux-x86_64 /usr/bin/envtpl \`\`\` diff --git a/README.md b/README.md index ee90296..e6e0417 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,13 @@ Do not edit this file. Edit 'docs/templates/README.md.j2' instead and run 'make | OS | Arch | Version | | | ------------ | ------- | --------------------- | ---- | -| OSX (Darwin) | x86_64 | 1.0.0 (latest) | [Download](https://github.com/busyloop/envcat/releases/tag/v1.0.0) | -| Linux | x86_64 | 1.0.0 (latest) | [Download](https://github.com/busyloop/envcat/releases/tag/v1.0.0) | -| Linux | aarch64 | 1.0.0 (latest) | [Download](https://github.com/busyloop/envcat/releases/tag/v1.0.0) | +| OSX (Darwin) | x86_64 | 1.0.1 (latest) | [Download](https://github.com/busyloop/envcat/releases/tag/v1.0.1) | +| Linux | x86_64 | 1.0.1 (latest) | [Download](https://github.com/busyloop/envcat/releases/tag/v1.0.1) | +| Linux | aarch64 | 1.0.1 (latest) | [Download](https://github.com/busyloop/envcat/releases/tag/v1.0.1) | #### Dockerfile -See the [download page](https://github.com/busyloop/envcat/releases/tag/v1.0.0) for an example Dockerfile. :whale: +See the [download page](https://github.com/busyloop/envcat/releases/tag/v1.0.1) for an example Dockerfile. :whale: ## Usage @@ -60,7 +60,7 @@ echo "{{BIND}}:{{PORT | default('443')}} {{NAME}}" | envcat -f j2 -c PORT:?port ## Templating -With `-f j2` envcat renders a jinja2 template from _stdin_ to _stdout_. +With `-f j2`, or when called by the name `envtpl`, envcat renders a jinja2 template from _stdin_ to _stdout_. Environment variables are available as `{{VAR}}`. envcat will abort with code 5 if your template references an undefined variable, @@ -78,15 +78,49 @@ unset NOPE echo "{{FOO}}" | envcat -f j2 FOO # => a,b,c echo "{{NOPE | default('empty')}}" | envcat -f j2 NOPE # => empty echo "{% for x in FOO | split(',') %}{{x}}{% endfor %}" | envcat -f j2 FOO # => abc -echo "{% if FOO == 'd,e,f' %}A{% else %}B{% endif %}" | envcat -f j2 FOO # => B -echo "{% if BAR | int + 1 == 42 %}yes{% endif %}" | envcat -f j2 BAR # => yes +echo "{% if FOO == 'd,e,f' %}A{% else %}B{% endif %}" | envtpl FOO # => B +echo "{% if BAR | int + 1 == 42 %}yes{% endif %}" | envtpl BAR # => yes ``` -If you need more, please consult the [jinja2 documentation](https://jinja.palletsprojects.com/en/2.11.x/templates/). -**Note:** -There are some [subtle differences](https://straight-shoota.github.io/crinja/#:~:text=Differences%20from%20Jinja2) between [the jinja2 library used in envcat](https://straight-shoota.github.io/crinja/) and the original Python jinja2. -But likely none that you will encounter in normal usage. +## Template syntax + +Envcat supports most jinja2 syntax and [builtin filters](https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-builtin-filters). + +On top it provides the following additional filters: + +#### b64encode, b64encode_urlsafe + +```bash +export FOO="hello? world?" + +# b64encode, b64encode_urlsafe +echo "{{FOO | b64encode}}" | envtpl FOO # => aGVsbG8/IHdvcmxkPw== +echo "{{FOO | b64encode_urlsafe}}" | envtpl FOO # => aGVsbG8_IHdvcmxkPw== +``` + +#### b64decode + +```bash +export B64_REGULAR="aGVsbG8/IHdvcmxkPw==" +export B64_URLSAFE="aGVsbG8_IHdvcmxkPw==" + +echo "{{B64_REGULAR | b64decode}}" | envtpl 'B*' # => hello? world? +echo "{{B64_URLSAFE | b64decode}}" | envtpl 'B*' # => hello? world? +``` + +#### split + + +```bash +export FOO=a,b,c + +echo "{% for x in FOO | split(',') %}{{x}}..{% endfor %}" | envtpl FOO # => a..b..c.. +``` + +**Note:** +Envcat uses a [Crystal implementation of the jinja2 template engine](https://straight-shoota.github.io/crinja/). +Python expressions are **not** supported. ## Checks @@ -210,7 +244,3 @@ $ envcat -f json VARS_ETF:etf A B C 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request - -## Contributors - -- [moe](https://github.com/m-o-e) - creator and maintainer diff --git a/docs/templates/README.md.j2 b/docs/templates/README.md.j2 index b0d9bc8..f5173de 100644 --- a/docs/templates/README.md.j2 +++ b/docs/templates/README.md.j2 @@ -63,7 +63,7 @@ echo "{{BIND}}:{{PORT | default('443')}} {{NAME}}" | envcat -f j2 -c PORT:?port ## Templating -With `-f j2` envcat renders a jinja2 template from _stdin_ to _stdout_. +With `-f j2`, or when called by the name `envtpl`, envcat renders a jinja2 template from _stdin_ to _stdout_. Environment variables are available as `{{VAR}}`. envcat will abort with code 5 if your template references an undefined variable, @@ -81,15 +81,49 @@ unset NOPE echo "{{FOO}}" | envcat -f j2 FOO # => a,b,c echo "{{NOPE | default('empty')}}" | envcat -f j2 NOPE # => empty echo "{% for x in FOO | split(',') %}{{x}}{% endfor %}" | envcat -f j2 FOO # => abc -echo "{% if FOO == 'd,e,f' %}A{% else %}B{% endif %}" | envcat -f j2 FOO # => B -echo "{% if BAR | int + 1 == 42 %}yes{% endif %}" | envcat -f j2 BAR # => yes +echo "{% if FOO == 'd,e,f' %}A{% else %}B{% endif %}" | envtpl FOO # => B +echo "{% if BAR | int + 1 == 42 %}yes{% endif %}" | envtpl BAR # => yes ``` -If you need more, please consult the [jinja2 documentation](https://jinja.palletsprojects.com/en/2.11.x/templates/). -**Note:** -There are some [subtle differences](https://straight-shoota.github.io/crinja/#:~:text=Differences%20from%20Jinja2) between [the jinja2 library used in envcat](https://straight-shoota.github.io/crinja/) and the original Python jinja2. -But likely none that you will encounter in normal usage. +## Template syntax + +Envcat supports most jinja2 syntax and [builtin filters](https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-builtin-filters). + +On top it provides the following additional filters: + +#### b64encode, b64encode_urlsafe + +```bash +export FOO="hello? world?" + +# b64encode, b64encode_urlsafe +echo "{{FOO | b64encode}}" | envtpl FOO # => aGVsbG8/IHdvcmxkPw== +echo "{{FOO | b64encode_urlsafe}}" | envtpl FOO # => aGVsbG8_IHdvcmxkPw== +``` + +#### b64decode + +```bash +export B64_REGULAR="aGVsbG8/IHdvcmxkPw==" +export B64_URLSAFE="aGVsbG8_IHdvcmxkPw==" + +echo "{{B64_REGULAR | b64decode}}" | envtpl 'B*' # => hello? world? +echo "{{B64_URLSAFE | b64decode}}" | envtpl 'B*' # => hello? world? +``` + +#### split + + +```bash +export FOO=a,b,c + +echo "{% for x in FOO | split(',') %}{{x}}..{% endfor %}" | envtpl FOO # => a..b..c.. +``` + +**Note:** +Envcat uses a [Crystal implementation of the jinja2 template engine](https://straight-shoota.github.io/crinja/). +Python expressions are **not** supported. ## Checks @@ -161,8 +195,4 @@ $ envcat -f json VARS_ETF:etf A B C 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request - -## Contributors - -- [moe](https://github.com/m-o-e) - creator and maintainer {% endraw %} diff --git a/shard.yml b/shard.yml index ab1f5fb..421b3ec 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: envcat -version: 1.0.0 +version: 1.0.1 authors: - moe diff --git a/src/envcat/cli.cr b/src/envcat/cli.cr index 77d88e2..abc2e6c 100644 --- a/src/envcat/cli.cr +++ b/src/envcat/cli.cr @@ -29,9 +29,9 @@ class Envcat::Cli Toka.mapping({ format: { type: String, - default: Format::DEFAULT, + default: Envcat::Cli.default_format, value_name: "FORMAT", - description: Format.keys.sort!.join("|") + " (default: #{Format::DEFAULT})", + description: Format.keys.sort!.join("|") + " (default: #{Envcat::Cli.default_format})", }, check: { type: Array(String), @@ -53,6 +53,10 @@ class Envcat::Cli help: false, }) + def self.default_format + PROGRAM_NAME.try &.includes?("envtpl") ? "j2" : Format::DEFAULT + end + def self.help String.build(4096) do |s| s.puts "FORMAT"