From 248b7a5b779889c61c5a57143fbc5e80ee7ce6ba Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 31 Oct 2022 20:10:18 +0100 Subject: [PATCH] fix: allow escaping of commas in plugin list options (#142) --- cmd/drone-docker-buildx/config.go | 13 +++++++------ cmd/drone-docker-buildx/main.go | 3 +++ plugin/docker.go | 2 +- plugin/impl.go | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/drone-docker-buildx/config.go b/cmd/drone-docker-buildx/config.go index 66b5dac..671cfc2 100644 --- a/cmd/drone-docker-buildx/config.go +++ b/cmd/drone-docker-buildx/config.go @@ -2,6 +2,7 @@ package main import ( "github.com/thegeeklab/drone-docker-buildx/plugin" + "github.com/thegeeklab/drone-plugin-lib/v2/drone" "github.com/urfave/cli/v2" ) @@ -202,12 +203,12 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { Destination: &settings.Build.Target, Category: category, }, - &cli.StringSliceFlag{ - Name: "cache-from", - EnvVars: []string{"PLUGIN_CACHE_FROM"}, - Usage: "images to consider as cache sources", - Destination: &settings.Build.CacheFrom, - Category: category, + &cli.GenericFlag{ + Name: "cache-from", + EnvVars: []string{"PLUGIN_CACHE_FROM"}, + Usage: "images to consider as cache sources", + Value: &drone.StringSliceFlag{}, + Category: category, }, &cli.StringFlag{ Name: "cache-to", diff --git a/cmd/drone-docker-buildx/main.go b/cmd/drone-docker-buildx/main.go index 83ce2e3..baa3888 100644 --- a/cmd/drone-docker-buildx/main.go +++ b/cmd/drone-docker-buildx/main.go @@ -9,6 +9,7 @@ import ( "github.com/thegeeklab/drone-docker-buildx/plugin" "github.com/urfave/cli/v2" + "github.com/thegeeklab/drone-plugin-lib/v2/drone" "github.com/thegeeklab/drone-plugin-lib/v2/urfave" ) @@ -45,6 +46,8 @@ func run(settings *plugin.Settings) cli.ActionFunc { return func(ctx *cli.Context) error { urfave.LoggingFromContext(ctx) + settings.Build.CacheFrom = ctx.Generic("cache-from").(*drone.StringSliceFlag).Get() + plugin := plugin.New( *settings, urfave.PipelineFromContext(ctx), diff --git a/plugin/docker.go b/plugin/docker.go index 5ece2c3..7e08116 100644 --- a/plugin/docker.go +++ b/plugin/docker.go @@ -87,7 +87,7 @@ func commandBuild(build Build, dryrun bool) *exec.Cmd { if build.NoCache { args = append(args, "--no-cache") } - for _, arg := range build.CacheFrom.Value() { + for _, arg := range build.CacheFrom { args = append(args, "--cache-from", arg) } if build.CacheTo != "" { diff --git a/plugin/impl.go b/plugin/impl.go index 296a86d..58cab52 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -53,7 +53,7 @@ type Build struct { ArgsEnv cli.StringSlice // Docker build args from env Target string // Docker build target Pull bool // Docker build pull - CacheFrom cli.StringSlice // Docker build cache-from + CacheFrom []string // Docker build cache-from CacheTo string // Docker build cache-to Compress bool // Docker build compress Repo string // Docker build repository