Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace env var crunching with neat xargs trick #194

Closed
sanmiguel opened this issue Mar 22, 2017 · 3 comments · Fixed by #480
Closed

Replace env var crunching with neat xargs trick #194

sanmiguel opened this issue Mar 22, 2017 · 3 comments · Fixed by #480

Comments

@sanmiguel
Copy link
Collaborator

Use the trick here: https://gist.github.com/judy2k/7656bfe3b322d669ef75364a46327836

to be able to avoid having to manually touch every single env var in https://github.com/kerl/kerl/blob/master/kerl#L51-L138

@jadeallenx
Copy link
Collaborator

This is a neat trick too: https://stackoverflow.com/a/30969768

Might be relevant!

@paulo-ferraz-oliveira
Copy link
Contributor

paulo-ferraz-oliveira commented Aug 15, 2023

to be able to avoid having to manually touch every single env var in https://github.com/kerl/kerl/blob/master/kerl#L51-L138

The file pointed too has since changed quite a lot. I'll try to get a reference as to the one you were mentioning 6+ years ago.

Edit: https://github.com/kerl/kerl/blob/1.4.2/kerl#L51-L138 (?)

Edit: the trick @sanmiguel references, though, has already gone through multiple iterations, too...

@paulo-ferraz-oliveira
Copy link
Contributor

paulo-ferraz-oliveira commented Oct 17, 2023

I could simplify it via

act_on_kerl_cfgs() {
    # $1: action - cache | restore (default)

    for _KERL_CFG in ${_KERL_CFGS_AUX}; do
        if [ $1 == cache ]; then
            eval "_KERL_CFG_VAR=\$${_KERL_CFG}"
            eval "_KERL_TARGET_VAR=__${_KERL_CFG}"
        elif [ $1 == restore ]; then
            eval "_KERL_CFG_VAR=\$__${_KERL_CFG}"
            eval "_KERL_TARGET_VAR=${_KERL_CFG}"
        fi
        if [ -n "${_KERL_CFG_VAR}" ]; then
            eval "$_KERL_TARGET_VAR=$_KERL_CFG_VAR"
        fi
    done
}

instead of hand-picked variable names we save them with a __ prefix to later recover them, in the same fashion as the code does, these days, only the list to maintain becomes

_KERL_CFGS="\
OTP_GITHUB_URL=https://github.com/erlang/otp \
KERL_CONFIGURE_OPTIONS= \
KERL_CONFIGURE_APPLICATIONS= \
KERL_CONFIGURE_DISABLE_APPLICATIONS= \
KERL_SASL_STARTUP= \
KERL_DEPLOY_SSH_OPTIONS= \
KERL_DEPLOY_RSYNC_OPTIONS= \
KERL_INSTALL_MANPAGES= \
KERL_INSTALL_HTMLDOCS= \
KERL_BUILD_PLT= \
KERL_BUILD_DOCS= \
KERL_DOC_TARGETS=chunks \
KERL_BUILD_BACKEND= \
KERL_RELEASE_TARGET= \
"

which hopefully is much simpler to read. I'll pr soon, when the outstanding requests are dealt with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants