Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pflag slice value interface for image types #5575

Merged
32 changes: 18 additions & 14 deletions cmd/skaffold/app/flags/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,18 @@ type image struct {
artifact *build.Artifact
}

// String Implements String() method for pflag interface and
// returns a comma separated list of images.
func (i *Images) String() string {
// GetSlice Implements GetSlice() method for pflag SliceValue interface and
// returns a slice image names.
func (i *Images) GetSlice() []string {
names := make([]string, len(i.images))
for i, image := range i.images {
names[i] = image.name
}
return strings.Join(names, ",")
return names
}

// Usage Implements Usage() method for pflag interface
func (i *Images) Usage() string {
return i.usage
}

// Set Implements Set() method for pflag interface
func (i *Images) Set(value string) error {
// Append Implements Append() method for pflag SliceValue interface
func (i *Images) Append(value string) error {
a, err := convertImageToArtifact(value)
if err != nil {
return err
Expand All @@ -61,9 +56,18 @@ func (i *Images) Set(value string) error {
return nil
}

// Type Implements Type() method for pflag interface
func (i *Images) Type() string {
return fmt.Sprintf("%T", i)
// Replace Implements Replace() method for pflag SliceValue interface
func (i *Images) Replace(images []string) error {
newImages := make([]image, len(i.images))
sladyn98 marked this conversation as resolved.
Show resolved Hide resolved
for _, value := range images {
a, err := convertImageToArtifact(value)
if err != nil {
return err
}
newImages = append(newImages, image{name:value, artifact:a})
i.images = newImages
}
return nil
}
briandealwis marked this conversation as resolved.
Show resolved Hide resolved

// Artifacts returns an artifact representation for the corresponding image
Expand Down