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

Override config via environment #107

Open
jbergstroem opened this issue Apr 5, 2018 · 6 comments · May be fixed by #119
Open

Override config via environment #107

jbergstroem opened this issue Apr 5, 2018 · 6 comments · May be fixed by #119

Comments

@jbergstroem
Copy link

When playing with dockerfiles and multiple repos (main usecase for me is part of CI) it would be nice to be able to override specific config settings via environment; for instance YAMLLINT_CONFIG="line-length.max=81" yamllint foo.yaml. This makes it easier to override a few settings without having to check in a config in each repo you're testing against.

@adrienverge
Copy link
Owner

I agree it could be cool. But I'd rather have a YAML-formatted config, like for the -d option.

By the way, did you know you can already use this?

YAMLLINT_CONFIG="{extends: relaxed, rules: {line-length: {max: 81}}}"
yamllint -d "$YAMLLINT_CONFIG" foo.yaml

@jbergstroem
Copy link
Author

jbergstroem commented Apr 6, 2018

@adrienverge said: did you know you can already pass config as env?

Didn't. Thanks!

@adrienverge said: YAMLLINT_CONFIG=..

I considered format as well; suggested something different than YAML in my original comment because I felt a simpler dot notation was closer to your average bash experience. I guess it doesn't scale as well, but the idea was to have the option of changing "just the one thing"; not really passing a full config.

I guess there are two minor opportunities for improvements here. Consider a use case similar to:

# Override while calling this docker instance in your CI pipeline
ENV YAML_ARGS=""

# ...

CMD ["yamllint", "-d '${YAML_ARGS}'"]

..and overriding this from your ci script.

  1. Allowing "empty" configs by assuming they default:
$ docker run --rm -v $(PWD):/yaml sdesbure/yamllint yamllint -d "" .gitlab-ci.yml
invalid config: not a dict
  1. Avoiding -d by reading a defined environment variable

I guess both can be handled in wrappers but I thought it be worth bringing it up. Feel free to close this issue unless you feel we should make either improvement actionable.

@adrienverge
Copy link
Owner

Hey,

Both 1. and 2. make sense!
Contributions are welcome (they need to come with tests).

jbergstroem pushed a commit to jbergstroem/yamllint that referenced this issue Jun 28, 2018
This is a "minor" abi break since empty configs are
disregarded instead of failing.

Fixes: adrienverge#107
@jbergstroem jbergstroem linked a pull request Jun 28, 2018 that will close this issue
@grzesuav
Copy link
Contributor

grzesuav commented Aug 1, 2019

@adrienverge When I have config in file and want just to override one rule, can I do it with existing mechanism somehow ?

@adrienverge
Copy link
Owner

@grzesuav you can do this:

YAMLLINT_CONFIG="{extends: /my/config/file.yaml, rules: {line-length: {max: 20}}}"
yamllint -d "$YAMLLINT_CONFIG" foo.yaml

@grzesuav
Copy link
Contributor

grzesuav commented Aug 1, 2019

ok, thanks :)

anyway I think overriding specific setting with env variable would be useful in this case. Do you have any preference around the behavior ?

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

Successfully merging a pull request may close this issue.

3 participants