mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 10:03:42 +08:00 
			
		
		
		
	This will allow result printing to work with the remote controller (though this currently causes a panic, to be fixed in a follow-up). Signed-off-by: Justin Chadwell <me@jedevc.com>
		
			
				
	
	
		
			38 lines
		
	
	
		
			773 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			773 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package buildflags
 | 
						|
 | 
						|
import (
 | 
						|
	"encoding/csv"
 | 
						|
	"strings"
 | 
						|
 | 
						|
	controllerapi "github.com/docker/buildx/controller/pb"
 | 
						|
	"github.com/pkg/errors"
 | 
						|
)
 | 
						|
 | 
						|
func ParsePrintFunc(str string) (*controllerapi.PrintFunc, error) {
 | 
						|
	if str == "" {
 | 
						|
		return nil, nil
 | 
						|
	}
 | 
						|
	csvReader := csv.NewReader(strings.NewReader(str))
 | 
						|
	fields, err := csvReader.Read()
 | 
						|
	if err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	f := &controllerapi.PrintFunc{}
 | 
						|
	for _, field := range fields {
 | 
						|
		parts := strings.SplitN(field, "=", 2)
 | 
						|
		if len(parts) == 2 {
 | 
						|
			if parts[0] == "format" {
 | 
						|
				f.Format = parts[1]
 | 
						|
			} else {
 | 
						|
				return nil, errors.Errorf("invalid print field: %s", field)
 | 
						|
			}
 | 
						|
		} else {
 | 
						|
			if f.Name != "" {
 | 
						|
				return nil, errors.Errorf("invalid print value: %s", str)
 | 
						|
			}
 | 
						|
			f.Name = field
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return f, nil
 | 
						|
}
 |