Add a new ExtractVariables function to compose/template package#1249
Merged
vdemeester merged 1 commit intoAug 1, 2018
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1249 +/- ##
==========================================
+ Coverage 54.23% 54.29% +0.05%
==========================================
Files 268 268
Lines 17809 17843 +34
==========================================
+ Hits 9658 9687 +29
- Misses 7543 7546 +3
- Partials 608 610 +2 |
silvin-lubecki
approved these changes
Aug 1, 2018
| } | ||
| name := val | ||
| var defaultValue string | ||
| if strings.Contains(val, ":?") { |
Contributor
There was a problem hiding this comment.
nit
switch{
case string.Contains(val, ":?"):
name, _ = partition(val, ":?")
case strings.Contains(val, "?"):
name, _ = partition(val, "?")
...
}
return extractedValue{name: name, value: defaultValue}, true
}ec0cf60 to
c41cfcc
Compare
thaJeztah
approved these changes
Aug 1, 2018
Member
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM; left two comments, but don't think those are blockers, more future enhancements
| }, | ||
| { | ||
| dict: map[string]interface{}{ | ||
| "foo": "${bar:-foo}", |
Member
There was a problem hiding this comment.
Nested substitutions are not supported currently? (e.g. ${foo:-$bar})
Collaborator
Author
There was a problem hiding this comment.
I'm not actually sure abou that 😝
| }, | ||
| }, | ||
| } | ||
| for _, tc := range testCases { |
Member
There was a problem hiding this comment.
Could change this to subtests as a follow up?
It allows to get easily all the variables defined in a
composefile (the `map[string]interface{}` representation that
`loader.ParseYAML` returns at least) and their default value too.
This commit also does some small function extract on substitution
funcs to reduce a tiny bit duplication.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
c41cfcc to
afb87e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It allows to get easily all the variables defined in a
composefile (the
map[string]interface{}representation thatloader.ParseYAMLreturns at least) and their default value too.This commit also does some small function extract on substitution
funcs to reduce a tiny bit duplication.
Can be really useful for project that enhance the compose implementation like
docker/app.Signed-off-by: Vincent Demeester vincent@sbr.pm