qetza / replacetokens Goto Github PK
View Code? Open in Web Editor NEWCLI to replace tokens in text files with values from the command-line, files or environment variables.
License: MIT License
CLI to replace tokens in text files with values from the command-line, files or environment variables.
License: MIT License
Add a parameter --case-insensitive-paths
so that file matching for all paths (sources, variables...) is case insensitive.
We are using the replacetokens task to (among other things) replace placeholders in env files for docker compose.
These files have very specific requirements on escaping.
Currently we are using the "Replace Tokens" task, but it does not currently support escaping in these env files.
I realize this is a very specific use-case, but it is not possible to cover it with the custom-escaping config, due to the context-sensitive nature of the escaping.
Do you think it makes sense to add special escaping for *.env
files here?
Basically what we need is the bash script below, which works well (up to a few edge cases). A bash script in the pipeline does not have access to all the variables though, afaik.
# Generate sed s-command to replace one literal with another one.
# The key is assumed to contain only characters [A-Z_]
function sub() {
KEY="$1"
VALUE=$(printf '%s' "$2" | sed -e 's/[\|&]/\\&/g')
printf 's|#{%s}#|%s|g' "$KEY" "$VALUE"
}
# - Single quoted values need to have single quotes escaped.
# - Double quoted values need to have double quotes and backslashes escaped.
# - Double- und unquoted values need to have the dollar sign escaped.
VALUE_SQ=$(printf "%s" "$VALUE" | sed -e "s|'|\\\\'|g")
VALUE_DQ=$(printf "%s" "$VALUE" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g' -e 's|\$|$$|g')
VALUE_UQ=$(printf "%s" "$VALUE" | sed -e 's|\$|$$|g')
sed -i \
-e '/^[^=]*='\''/ '"$(sub "$KEY" "$VALUE_SQ")" \
-e '/^[^=]*="/ '"$(sub "$KEY" "$VALUE_DQ")" \
-e "$(sub "$KEY" "$VALUE_UQ")" \
"$FILE"
Add support for glob patterns when referencing a file in variables:
Most build systems are case insensitive for their variables
so the lib should be case insensitive too to avoid issue like qetza/replacetokens-task#8
To simplify the use of environment variables as variables add a new parameter --use-env
to initialize variables with all env variables:
--variables
will be optional if --use-env
is specified--variables
will override env variables if they have the same nameAdd a parameter --include-dot-paths
so that file starting with a dot (.
) are included in the glob results.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.