-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add a new ExtractVariables
function to compose/template
package
#1249
Add a new ExtractVariables
function to compose/template
package
#1249
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cli/compose/template/template.go
Outdated
} | ||
name := val | ||
var defaultValue string | ||
if strings.Contains(val, ":?") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; left two comments, but don't think those are blockers, more future enhancements
}, | ||
{ | ||
dict: map[string]interface{}{ | ||
"foo": "${bar:-foo}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested substitutions are not supported currently? (e.g. ${foo:-$bar}
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure abou that 😝
}, | ||
}, | ||
} | ||
for _, tc := range testCases { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could change this to subtests as a follow up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sir ! 😝
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👼
It allows to get easily all the variables defined in a
composefile (the
map[string]interface{}
representation thatloader.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.
Can be really useful for project that enhance the compose implementation like
docker/app
.Signed-off-by: Vincent Demeester vincent@sbr.pm