@@ -155,36 +155,29 @@ func BuildPortForwardExpression(portForwards []string) (string, error) {
155155 return "" , nil
156156 }
157157
158- expr := `.portForwards += [`
158+ ports := make ([] string , len ( portForwards ))
159159 for i , spec := range portForwards {
160160 hostPort , guestPort , isStatic , err := ParsePortForward (spec )
161161 if err != nil {
162162 return "" , err
163163 }
164- expr += fmt .Sprintf (`{"guestPort": %q, "hostPort": %q, "static": %v}` , guestPort , hostPort , isStatic )
165- if i < len (portForwards )- 1 {
166- expr += ","
167- }
164+ ports [i ] = fmt .Sprintf (`{"guestPort": %q, "hostPort": %q, "static": %v}` , guestPort , hostPort , isStatic )
168165 }
169- expr += `]`
166+ expr := fmt . Sprintf ( ".portForwards += [%s]" , strings . Join ( ports , "," ))
170167 return expr , nil
171168}
172169
173170func buildMountListExpression (ss []string ) (string , error ) {
174- expr := `[`
171+ mounts := make ([] string , len ( ss ))
175172 for i , s := range ss {
176173 writable := strings .HasSuffix (s , ":w" )
177- loc := strings .TrimSuffix (s , ":w" )
178- loc , err := localpathutil .Expand (loc )
174+ loc , err := localpathutil .Expand (strings .TrimSuffix (s , ":w" ))
179175 if err != nil {
180176 return "" , err
181177 }
182- expr += fmt .Sprintf (`{"location": %q, "mountPoint": %q, "writable": %v}` , loc , loc , writable )
183- if i < len (ss )- 1 {
184- expr += ","
185- }
178+ mounts [i ] = fmt .Sprintf (`{"location": %q, "mountPoint": %q, "writable": %v}` , loc , loc , writable )
186179 }
187- expr += `]`
180+ expr := fmt . Sprintf ( "[%s]" , strings . Join ( mounts , "," ))
188181 return expr , nil
189182}
190183
@@ -206,14 +199,11 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
206199 if err != nil {
207200 return nil , err
208201 }
209- expr := `.dns += [`
202+ ips := make ([] string , len ( ipSlice ))
210203 for i , ip := range ipSlice {
211- expr += fmt .Sprintf ("%q" , ip )
212- if i < len (ipSlice )- 1 {
213- expr += ","
214- }
204+ ips [i ] = `"` + ip .String () + `"`
215205 }
216- expr += ` ] | .dns |= unique | .hostResolver.enabled=false`
206+ expr := fmt . Sprintf ( ".dns += [%s ] | .dns |= unique | .hostResolver.enabled=false" , strings . Join ( ips , "," ))
217207 logrus .Warnf ("Disabling HostResolver, as custom DNS addresses (%v) are specified" , ipSlice )
218208 return []string {expr }, nil
219209 },
@@ -293,23 +283,20 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
293283 if err != nil {
294284 return nil , err
295285 }
296- expr := `.networks += [`
286+ networks := make ([] string , len ( ss ))
297287 for i , s := range ss {
298288 // CLI syntax is still experimental (YAML syntax is out of experimental)
299289 switch {
300290 case s == "vzNAT" :
301- expr + = `{"vzNAT": true}`
291+ networks [ i ] = `{"vzNAT": true}`
302292 case strings .HasPrefix (s , "lima:" ):
303293 network := strings .TrimPrefix (s , "lima:" )
304- expr + = fmt .Sprintf (`{"lima": %q}` , network )
294+ networks [ i ] = fmt .Sprintf (`{"lima": %q}` , network )
305295 default :
306- return nil , fmt .Errorf ("network name must be \" vzNAT\" or \" lima:*\" , got %q" , s )
307- }
308- if i < len (ss )- 1 {
309- expr += ","
296+ return nil , fmt .Errorf (`network name must be "vzNAT" or "lima:*", got %q` , s )
310297 }
311298 }
312- expr += ` ] | .networks |= unique_by(.lima)`
299+ expr := fmt . Sprintf ( `.networks += [%s ] | .networks |= unique_by(.lima)`, strings . Join ( networks , "," ))
313300 return []string {expr }, nil
314301 },
315302 false ,
0 commit comments