5
5
"context"
6
6
"errors"
7
7
"fmt"
8
+ "os"
8
9
"strings"
9
10
"text/template"
10
11
@@ -29,6 +30,7 @@ var commonCmdData common.CmdData
29
30
func NewExportCmd (ctx context.Context ) * cobra.Command {
30
31
var tagTemplateList []string
31
32
var addLabelArray []string
33
+ var addLabelSeparator string
32
34
33
35
ctx = common .NewContextWithCmdData (ctx , & commonCmdData )
34
36
cmd := common .SetCommandContext (ctx , & cobra.Command {
@@ -66,18 +68,17 @@ func NewExportCmd(ctx context.Context) *cobra.Command {
66
68
return fmt .Errorf ("required at least one tag template: use the --tag option to specify templates" )
67
69
}
68
70
69
- var addLabelMap map [string ]string
70
- var err error
71
- {
72
- addLabelArray := append (util .PredefinedValuesByEnvNamePrefix ("WERF_EXPORT_ADD_LABEL_" ), addLabelArray ... )
73
- addLabelMap , err = common .InputArrayToKeyValueMap (addLabelArray , "=" , "," )
74
- if err != nil {
75
- common .PrintHelp (cmd )
76
- return fmt .Errorf ("unsupported --add-label value: %w" , err )
77
- }
71
+ result , err := common .InputArrayToKeyValueMap (
72
+ append (util .PredefinedValuesByEnvNamePrefix ("WERF_EXPORT_ADD_LABEL_" ), addLabelArray ... ),
73
+ addLabelSeparator ,
74
+ common .DefaultKeyValueSeparator ,
75
+ )
76
+ if err != nil {
77
+ common .PrintHelp (cmd )
78
+ return fmt .Errorf ("unsupported --add-label value: %w" , err )
78
79
}
79
80
80
- return run (ctx , args , tagTemplateList , addLabelMap )
81
+ return run (ctx , args , tagTemplateList , result )
81
82
},
82
83
})
83
84
@@ -130,9 +131,16 @@ func NewExportCmd(ctx context.Context) *cobra.Command {
130
131
It is necessary to use image name shortcut %image% or %image_slug% if multiple images are exported (e.g. REPO:TAG-%image% or REPO-%image%:TAG)` )
131
132
132
133
cmd .Flags ().StringArrayVarP (& addLabelArray , "add-label" , "" , []string {}, `Add label to exported images (can specify multiple).
133
- Format: labelName=labelValue.
134
+ Format: labelName=labelValue[<separator>labelName=labelValue ...]. The default separator is a newline ("\n"), but it can be customized using the --add-label-separator flag .
134
135
Also, can be specified with $WERF_EXPORT_ADD_LABEL_* (e.g. $WERF_EXPORT_ADD_LABEL_1=labelName1=labelValue1, $WERF_EXPORT_ADD_LABEL_2=labelName2=labelValue2)` )
135
136
137
+ defaultValue := common .DefaultAnnoAndLabelPairSeparator
138
+ if os .Getenv ("WERF_EXPORT_ADD_LABEL_SEPARATOR" ) != "" {
139
+ defaultValue = os .Getenv ("WERF_EXPORT_ADD_LABEL_SEPARATOR" )
140
+ }
141
+
142
+ cmd .Flags ().StringVarP (& addLabelSeparator , "add-label-separator" , "" , defaultValue , `Separator for --add-label values (default $WERF_EXPORT_ADD_LABEL_SEPARATOR or "\n")` )
143
+
136
144
return cmd
137
145
}
138
146
0 commit comments