From 1b4cedc7568dbbabc7c427f77ac7e60bf8bf450b Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 28 Jul 2018 22:44:04 +0800 Subject: [PATCH] feat: add force flag --- main.go | 6 ++++++ plugin.go | 5 +++++ plugin_test.go | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/main.go b/main.go index 31ae1ef..8d3726d 100644 --- a/main.go +++ b/main.go @@ -75,6 +75,11 @@ func main() { Usage: "Machine-readable output", EnvVar: "PLUGIN_READABLE", }, + cli.BoolFlag{ + Name: "force", + Usage: "Force a build to continue if artifacts exist, deletes existing artifacts", + EnvVar: "PLUGIN_FORCE", + }, } app.Version = Version @@ -119,6 +124,7 @@ func run(c *cli.Context) error { Debug: c.Bool("debug"), Parallel: c.Bool("parallel"), Readable: c.Bool("readable"), + Force: c.Bool("force"), }, } diff --git a/plugin.go b/plugin.go index 053e353..bb643bb 100644 --- a/plugin.go +++ b/plugin.go @@ -24,6 +24,7 @@ type ( Debug bool Parallel bool Readable bool + Force bool } // Plugin values @@ -103,6 +104,10 @@ func pkBuild(config Config) *exec.Cmd { args = append(args, "-machine-readable") } + if config.Force { + args = append(args, "-force") + } + args = append(args, config.Template) return exec.Command( "packer", diff --git a/plugin_test.go b/plugin_test.go index 9311b79..4a6b535 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -113,6 +113,16 @@ func Test_pkBuild(t *testing.T) { }, want: exec.Command("packer", "build", "-machine-readable", "foo.json"), }, + { + name: "add force flag", + args: args{ + config: Config{ + Template: "foo.json", + Force: true, + }, + }, + want: exec.Command("packer", "build", "-force", "foo.json"), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {