-
Notifications
You must be signed in to change notification settings - Fork 13
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
Feature: Add variables as arguments #29
Comments
Hi, is it merely because of convenience? The reason I'm asking is because scripting out having arguments last after some special syntax such as '--' via a wrapper-script is very doable and doesn't introduce another syntax for something that is already solved via widely used methods. |
Closing due to inactivity. For reference, here's a bash-script that inverts the way variables are passed: #!/bin/bash
delim_found=false
for arg in "$@"; do
if $delim_found; then
env_vars+=("$arg")
elif [ "$arg" == "--" ]; then
delim_found=true
else
command_args+=("$arg")
fi
done
# Execute the command with environment variables first
env "${env_vars[@]}" ain "${command_args[@]}" Usage with script saved as ain.sh. A single ain.sh template1.ain template2.ain -- VAR1=1 VAR2=2 |
As suggested in #29 have a special parameter after the template-names to make ain more usable. Instead of inputting vars before the invocation, --vars can be added afterwards and will set env-vars if not already defined, after the VAR=1 bash, but before any env-var file. NB If template-names are given over a pipe and adding --vars, ain will fail because of --vars not being recognized by flag. Test plan: * Verify ain -v still shows version. * Have a template with a ${VAR} in it. Have an .env file defining that ${VAR}. Verify .env file is still picked up. * Verify ain -b still works. * Have a template with a [Body]. Run ain with -l and verify the body-file is left when done. * Send a filename over a pipe (e g echo temp2.ain | ain temp.ain) and verify passing files over templates still works. * Have a template with two variables ${VAR1} and ${VAR2}. Set both before ain is invoked and pass other values with --vars (e g VAR1=1 VAR2=2 ain -p temp.ain --vars VAR1=aah VAR2=yes). Verify envvars set via bash takes precedence over --vars. * Edit the command line above and and remove one of the two bash-set variables. Verify --vars is only applied if the environment variable is not set. * Pass a malformed envvar missing and = sign, verify error message on malformed env-var value. * Pass --vars but do not pass any values. Verify error message on missing envvar values.
Hi @l1n3n01z ! I thought about this some more and decided to add Not only does it make arrow up easier, but on windows cmd.exe setting environment-variables is involved, and --vars will help there. It's on master right now but hasn't been released yet. |
Passing variables as environment variables is fine for configuration variables, but having used ain a bit, I feel that passing variables as arguments would be much more natural when the variable in question varies often. This applies both when scripting and on the command line.
Using a double hyphen to denote that the following arguments are variables might be a good way to do this. It would allow easy editing of parameters when calling the same endpoint a few times.
$ ain -e config.env base.ain specific_query.ain -- --id=2
push up arrow and change the id
$ ain -e config.env base.ain specific_query.ain -- --id=3
When scripting
NB: I'm using camelCase for my variables that I know change often
Before
After
The text was updated successfully, but these errors were encountered: