go-arg
go-arg copied to clipboard
Feature: accept custom Environment map (+ refactoring tests)
The core of this PR is the addition of an Environment map[string]string field in type Config struct{...}, that makes it possible to pass custom environment variables to be use or to override the process' environment variables. It's a small, simple change: https://github.com/alexflint/go-arg/pull/227/commits/c14b278ccf4b685438e57b107aa5e87e85f5fc2d
The goal is to make it more flexible to use in situations where environment variables will be loaded from different sources, and are not yet (and should not be) present in the process environment.
As an example use case, I'm using this to validate the correctness, during CI (so long before actual deployment) of some .env.* files with a significant number of environment variables that have certain requirements (e.g., value of variable X cannot be less than half the value of variable Y).
Unit tests were added to verify the functionality.
If this PR is merged, I'd suggest tagging it bumping to the next minor version (1.5.0 as of now) to follow semantic versioning, as it adds new features to the public API.
This PR also implements a few other changes that, while not changing any of the functionality, represent the bulk of the volume of changes, and may improve developer experience for development of the project:
- addresses some simple complaints from various linters
- refactors and cleans up tests, adding t.Helper() calls, using t.Setenv instead of os.Setenv, reducing unnecessary
require.NoError(t, err). - bumps dependency versions
@alexflint — please let me know your thoughts. Thanks!
Hey @bfreis sorry for leaving this so long without a response! Most of the lint-related fixes here I'd rather not incorporate as I don't think it's worth e.g. capturing the return of fmt.Println into _, _. I'd also rather not have an environment override map in the Config struct, though I'm open to passing in the complete set of environment variables explicitly. I'm going to close this for now.