mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 01:53:42 +08:00 
			
		
		
		
	The "reference" package was moved to a separate module, which was extracted
from b9b19409cf
Also update compose-go, which also switched to distribution/reference;
full diff: https://github.com/compose-spec/compose-go/compare/v1.18.3...v1.18.4
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
		
	
		
			
				
	
	
		
			29 lines
		
	
	
		
			710 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			710 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package buildflags
 | 
						|
 | 
						|
import (
 | 
						|
	"strings"
 | 
						|
 | 
						|
	"github.com/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
 | 
						|
}
 |