Skip to content

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

Merged
vdemeester merged 1 commit into
docker:masterfrom
vdemeester:compose-template-pkg-enhancement
Aug 1, 2018
Merged

vdemeester merged 1 commit into
docker:masterfrom
vdemeester:compose-template-pkg-enhancement

Conversation

@vdemeester

Copy link
Copy Markdown
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

codecov-io commented Jul 31, 2018 •

Copy link
Copy Markdown

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

@silvin-lubecki silvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread cli/compose/template/template.go Outdated
}
name := val
var defaultValue string
if strings.Contains(val, ":?") {

Copy link
Copy Markdown
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

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@vdemeester vdemeester left a comment

Copy link
Copy Markdown
Collaborator Author

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