feat: allow commas in --image-label but not multiple labels #1190
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.
Resolves #622
Context
Currently,
--image-label
expects a list ofkey=value
labels separated by commas. This means it is impossible to have labels whose value contain commas.This is problematic for descriptions (as shown in #622) but also labels that mandate commas like
moby.buildkit.frontend.caps
(e.g.moby.buildkit.frontend.caps=moby.buildkit.frontend.inputs,moby.buildkit.frontend.contexts
).Those commas also can't be escaped to make
pflag
keep the values as one label.Fix
TL;DR: this change might be considered a breaking change due to CLI flags not doing the exact same thing as before.
The issue can be solved easily by replacing
StringSliceVar
withStringArrayVar
. However, it does mean--image-label foo=bar,baz=qux
will stay as["foo=bar,baz=qux"]
instead of the current["foo=bar", "baz=qux"]
which might be unexpected for current users of--image-label
.From the name (
--image-label
) I did expect it to take only a single value instead of a comma-separated one but the description (Which labels (key=value) to add to the image.
) seems to say the opposite.Alternative
Trying to support both options in one flag (
--image-label
) seems difficult and quite error-prone so might it be possible to consider adding a new option (e.g.--image-add-label
,--image-single-label
, etc) which can support label with commas?