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

Add a new ExtractVariables function to compose/template package #1249

Merged

Conversation

vdemeester
Copy link
Collaborator

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.

Can be really useful for project that enhance the compose implementation like docker/app.

Signed-off-by: Vincent Demeester vincent@sbr.pm

@codecov-io
Copy link

codecov-io commented Jul 31, 2018

Codecov Report

Merging #1249 into master will increase coverage by 0.05%.
The diff coverage is 89.09%.

@@            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

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
name := val
var defaultValue string
if strings.Contains(val, ":?") {
Copy link
Contributor

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
}

@vdemeester vdemeester force-pushed the compose-template-pkg-enhancement branch from ec0cf60 to c41cfcc Compare August 1, 2018 13:58
Copy link
Member

@thaJeztah thaJeztah left a 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}",
Copy link
Member

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})

Copy link
Collaborator Author

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 {
Copy link
Member

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?

Copy link
Collaborator Author

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>
@vdemeester vdemeester force-pushed the compose-template-pkg-enhancement branch from c41cfcc to afb87e4 Compare August 1, 2018 14:12
Copy link
Collaborator Author

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👼

@vdemeester vdemeester merged commit da544e8 into docker:master Aug 1, 2018
@GordonTheTurtle GordonTheTurtle added this to the 18.09.0 milestone Aug 1, 2018
@vdemeester vdemeester deleted the compose-template-pkg-enhancement branch August 1, 2018 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants