mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 18:13:42 +08:00 
			
		
		
		
	Strongly typing the API allows us to perform all command line parsing fully on the client-side, where we have access to the client local directory and all the client environment variables, which may not be available on the remote server. Additionally, the controller api starts to look a lot like build.Options, so at some point in the future there may be an oppportunity to merge the two, which would allow both build and bake to execute through the controller, instead of needing to maintain multiple code paths. Signed-off-by: Justin Chadwell <me@jedevc.com>
		
			
				
	
	
		
			29 lines
		
	
	
		
			717 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			717 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package buildflags
 | 
						|
 | 
						|
import (
 | 
						|
	"strings"
 | 
						|
 | 
						|
	"github.com/docker/distribution/reference"
 | 
						|
	"github.com/pkg/errors"
 | 
						|
)
 | 
						|
 | 
						|
func ParseContextNames(values []string) (map[string]string, error) {
 | 
						|
	if len(values) == 0 {
 | 
						|
		return nil, nil
 | 
						|
	}
 | 
						|
	result := make(map[string]string, len(values))
 | 
						|
	for _, value := range values {
 | 
						|
		kv := strings.SplitN(value, "=", 2)
 | 
						|
		if len(kv) != 2 {
 | 
						|
			return nil, errors.Errorf("invalid context value: %s, expected key=value", value)
 | 
						|
		}
 | 
						|
		named, err := reference.ParseNormalizedNamed(kv[0])
 | 
						|
		if err != nil {
 | 
						|
			return nil, errors.Wrapf(err, "invalid context name %s", kv[0])
 | 
						|
		}
 | 
						|
		name := strings.TrimSuffix(reference.FamiliarString(named), ":latest")
 | 
						|
		result[name] = kv[1]
 | 
						|
	}
 | 
						|
	return result, nil
 | 
						|
}
 |