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

Consider allowing individual '--vars' via the command line instead of requiring a file #439

Closed
mkobit opened this issue Apr 16, 2019 · 3 comments · Fixed by #534
Closed

Consider allowing individual '--vars' via the command line instead of requiring a file #439

mkobit opened this issue Apr 16, 2019 · 3 comments · Fixed by #534

Comments

@mkobit
Copy link
Contributor

@mkobit mkobit commented Apr 16, 2019

Some shells don't have process substitution, and environment variables can't be structured as easily when you want to pass in multiple inputs. It could be useful to pass in --vars without modifying a file for adhoc testing, or for just running things without requiring a vars file at all.

A possible example

goss --var ip.addr='[1.1.1.1, 2.2.2.2]' validate
@aelsabbahy

This comment has been minimized.

Copy link
Owner

@aelsabbahy aelsabbahy commented Dec 27, 2019

I'm not sure how easy it will be to implement this in Go the way you've requested to be honest. (handling complex/nested) objects.

Would allowing JSON on the CLI meet your needs? Or is that not a useful feature?

goss --vars '{"ip": {"addr": [1.1.1.1, 2.2.2.2]}}' validate

Tagging @pedroMMM since he 👍 this, would love your feedback also.

@pedroMMM

This comment has been minimized.

Copy link
Contributor

@pedroMMM pedroMMM commented Dec 27, 2019

In my use case, I was calling Goss from Packer and I needed to inject multiple runtime values alongside my variables file to Goss. In my case, I just got around it by forking and expanding the Goss Packer Provisioner to support exactly what you just described since the Provisioner was already moving the variables file to the instance.

I support adding a --vars-inline '{...}' variable since it will enable users to run Goss for ad hoc testing/debugging but also in more complex scenarios like mine. To be clear the --vars-inline will be loaded after the --vars which means that keys from inline (that overlap) will overwrite those that were sourced from the file. This will have to be made clear to users.

@aelsabbahy

This comment has been minimized.

Copy link
Owner

@aelsabbahy aelsabbahy commented Dec 28, 2019

Yup, documentation should be clear that not only will vars-inline win, but no advanced deep merging will be done.

aelsabbahy added a commit that referenced this issue Feb 12, 2020
* Add --vars-inline that is capable of overwriting --vars

* Reinforce the --vars-inline overwrite of --vars

* Clean up the TemplateFilter based on Code Climate feedback

* Fix the Travis testing by ensuring all the checks are ran

* Apply suggestions from code review for incorrect environment variable syntax

Co-Authored-By: Ahmed Elsabbahy <aelsabbahy@users.noreply.github.com>

Co-authored-by: Ahmed Elsabbahy <aelsabbahy@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.