{"id":13587557,"url":"https://github.com/icy/genvsub","last_synced_at":"2025-03-17T05:32:03.135Z","repository":{"id":57530821,"uuid":"181131552","full_name":"icy/genvsub","owner":"icy","description":"Another way to substitute environment variables in shell format strings ${FOO}, designed for k8s stuff","archived":false,"fork":false,"pushed_at":"2023-03-20T19:21:54.000Z","size":77,"stargazers_count":12,"open_issues_count":2,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-22T00:22:22.003Z","etag":null,"topics":["helm","k8s","kustomization","shell","substitution","template-engine","terraform","variable"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-04-13T06:39:49.000Z","updated_at":"2024-02-12T11:19:56.000Z","dependencies_parsed_at":"2024-02-13T21:52:16.835Z","dependency_job_id":"50d0b8b7-8f6c-40fd-bd56-e87f24b44556","html_url":"https://github.com/icy/genvsub","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icy%2Fgenvsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icy%2Fgenvsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icy%2Fgenvsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icy%2Fgenvsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icy","download_url":"https://codeload.github.com/icy/genvsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243852484,"owners_count":20358271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["helm","k8s","kustomization","shell","substitution","template-engine","terraform","variable"],"created_at":"2024-08-01T15:06:15.909Z","updated_at":"2025-03-17T05:32:02.695Z","avatar_url":"https://github.com/icy.png","language":"Shell","readme":"![icy](https://github.com/icy/genvsub/workflows/icy/badge.svg)\n\n## Alternative to Gettext's envsubst\n\nSubstitutes environment variables in shell format strings,\nand can *raise error* if any environment is not set.\nThere are two kinds of format string `$FOO` and `${FOO}`.\nThis tool only works with the later form and can serve a simple\ntemplate engine for your shell scripts ;)\nThe program can also limit its action to a small set of variables\nwhose names match a predefined prefix/regexp.\n\n## TOC\n\n* [Usage](#usage)\n  * [Supported options](#supported-options)\n  * [Installation. Examples](#installation-examples)\n  * [Note on variable prefix](#note-on-variable-prefix)\n* [Development](#development)\n  * [Smoke tests](#smoke-tests)\n* [References](#references)\n* [License](#license)\n\n## Usage\n\n### Supported options\n\n* `-v`: Scan and output all occurrences of variables in the input.\n* `-u`: Raise error when environment variable is not set.\n        When being used with `-v`, the program scans through the whole\n        input; otherwise, the program stops immediately when there is\n        any undefined (environment) variable.\n* `-p regexp`: Limit substitution to variables that match this prefix.\n        You can use some regular expression as prefix.\n        Default to `[^}]+`. Can be used as an alternative\n        to `SHELL-FORMAT` option in the original GNU `envsubst`\n\nIt's highly recommended to use `-u` option. It's the original idea\nwhy this tool was written.\n\n### Installation. Examples\n\nStarting from `v1.2.2`, you can download binary files generated automatically\nby Github-Action action (via goreleaser tool). You find the files from\nthe release listing page: https://github.com/icy/genvsub/releases\n\nTo install on your laptop by local compiling process, please try the popular way\n\n    $ go get -v github.com/icy/genvsub\n    $ export PATH=$PATH:$(go env GOPATH)/bin\n\nIf you don't want to install, you can use it like this:\n\n    $ echo '${HOME}' |  go run github.com/icy/genvsub@latest -u\n    \nThe program works with `STDIN` and write their output to `STDOUT`\n\n    $ echo 'My home is $HOME'   | ./genvsub # This will output \"My home is $HOME\"\n    $ echo 'My home is ${HOME}' | ./genvsub # This will output \"My home is /home/your-home-path\"\n    $ echo 'Raise error with unset variable ${XXHOME}' | ./genvsub -u\n\nTo limit substitution to variables that match some prefix, use `-p` option:\n\n    $  echo 'var=${TEST_VAR}' | ./genvsub -u -p SAFE_\n    :: genvsub is reading from STDIN and looking for variables with regexp '\\${(SAFE_)}'\n    var=${TEST_VAR}\n\n    $ echo '${TEST_VAR}' | ./genvsub -u -p 'TEST_.*'\n    :: genvsub is reading from STDIN and looking for variables with regexp '\\${(TEST_.*)}'\n    \u003cTEST_VAR::error::variable_unset\u003e\n    :: Environment variable 'TEST_VAR' is not set.\n\nThe second command raises an error because the variable `TEST_VAR` matches\nthe expected prefix `TEST_` and its value is not set.\n\nYou can also specify exactly a few variables to be substituted\n(which is exactly an alternative to the `shell-format` option\nin the original GNU tool `envsubst`):\n\n    $ echo '${TEST_VAR}' | ./genvsub -u -p 'VAR_NAME_3|VAR_NAME_3|VAR_NAME_3'\n\n### Note on variable prefix\n\nWhen using `-p string` to specify the variable prefix, you can also use\nsome simple regular expression. However, please note that for the given\ninput argument `-p PREFIX`, the  program will build the final regexp\n`\\${(PREFIX)}`.\n\n1. Hence you can't use for example `-p '^FOO'`.\n2. You can also easily trick the program with some fun `PREFIX` ;)\n   However, as seen in\n   https://github.com/icy/genvsub/blob/33e68048c6fe4b6ca0befadbc9fa5c19055ede8b/sub.go#L42\n   the program enforces input data to follow the form `${VARIABLE_NAME}`.\n   I'm still thinking if we can allow more tricks here.\n\n## Problems\n\nClean up on Dec 18th 2020.\n\n## Development\n\n### Smoke tests\n\nWe don't likely have tests with `Golang`. We have some smoke tests instead.\n\n```\n$ make build tests\n```\n\nTests are written in `shell` script.\nPlease have a look at [tests/test.sh](tests/test.sh).\n\n### Ruby version\n\nRemoved on Dec 18th 2020.\n\n## References\n\n- [ ] Original tool: https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html\n    (which can't raise error if some variable is not set.)\n- [ ] https://github.com/a8m/envsubst : A Go tool; It tries to behave like Bash with some\n     advanced feature dealing with empty/non-set/default values\n     https://github.com/a8m/envsubst#docs; it can also raise error if some variable\n     is empty and/or not-set. This tool has a few features that I don't need,\n     and at the same time it doesn't have some features I need (reg-exp variable name\n     filter, strict variable naming format, bla bla)\n- [ ] https://github.com/gdvalle/envsub : A Rust tool; It introduces new syntax `%VAR%`,\n      which can be refined with `ENVSUB_PREFIX=%` and `ENVSUB_SUFFIX=%`.\n      When hitting unset variables it will exit rather than expanding as empty strings.\n      It also fully buffers input before writing, so in-place replacement is possible.\n- [ ] https://github.com/s12v/exec-with-secrets: Fetch configuration/secrets/variables\n      at run time, and provides them to your program. Now you have to rebuild your\n      docker images with the tool atop your original `executable` command.\n\n## License\n\nThis work is writtedn by Ky-Anh Huynh\nand it's released under a MIT license.\n","funding_links":[],"categories":["Shell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficy%2Fgenvsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficy%2Fgenvsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficy%2Fgenvsub/lists"}